A software framework is a set of source code or libraries which provide functionality common to a whole class of applications. While one library will usually provide one specific piece of functionality, frameworks will offer a broader range which are all often used by one type of application. Rather than rewriting commonly used logic, a programmer can leverage a framework which provides often used functionality, limiting the time required to build an application and reducing the possibility of introducing new bugs.
For example, a web application framework may provide user session management, data storage, and a templating system. A desktop application framework may provide user interface functionality and widgets (common GUI elements). Almost all frameworks control at least some aspect of an application's flow of execution.
There are many different types of frameworks, even within one classification of applications. Some offer little more than individual utility routines within a basic shell of an application. Others offer what is almost a complete application and require strict source code organization and other rules. Choosing the best framework for a project often requires a programmer to balance how much functionality they get from the framework against the flexibility they are left with.
Application frameworks offer a variety of advantages:
- Using code which has already been built, tested, and used by other programmers increases reliability and reduces programming time. In a corporation this code reuse effectively saves money.
- Software development teams can be split between those who program the framework and those who program the final complete application. This separation of tasks lets each team focus on more specific goals and use their individual strengths. For example, the programmers who are experts at user interface design might work on the client application while the security experts test and strengthen the framework upon which the application is built.
- Frameworks can provide security features which are often required for a common class of applications. This provides every application written with the framework to benefit from the added security without the extra time and cost of developing it. Examples include secure session management and escaping database input. (See Web application/Security.)
- By handling "lower level" tasks frameworks can assist with code modularity. Business logic, for example, can remain in the application while the mundane tasks of database connectivity and handling user logins can be handled separately in the framework.
- Frameworks often help enforce platform-specific best practices and rules. A desktop GUI framework, for example, may automatically build toolbars and buttons common to the local operating system. A web application framework may assist with encrypting user passwords or payment processing.
- Frameworks can assist in programming to design patterns and general best practices. For example, many frameworks are architected according to the Model-View-Controller design pattern.
- Upgrades to a framework can enhance application functionality without extra programming by the final application developer. If, for example, an e-commerce framework offers a new payment method, that option can automatically become available to the end user with no extra programming by the application developer.
There can be negative consequences to using a framework:
- Performance can sometimes degrade when common code is used. This sometimes occurs when a framework must check for the various scenarios in which it is used to determine a path of action. It can also occur with generalized code that is not optimized for a specific situation. Performance degradation, though, is often offset by the enhanced speed of development and quality of the final application.
- Frameworks often require a significant education to use efficiently and correctly (i.e. some have a high learning curve). Therefore specific frameworks very often become more valuable to individual programmers when they are used repeatedly. With each new project using the same framework, the learning curve becomes less of an issue and productivity increases.
- Functionality which needs to bypass or work around deficiencies in a framework can cause more programming issues than developing the full functionality in the first place. Good frameworks provide utility and structure while still leaving enough flexibility to not get in the way of the programmer. Some frameworks are so rigid and highly structured that choosing them for an inappropriate project can be disastrous. This is not the fault of the framework, but some are more generally suited and flexible than others. This must be carefully considered by those choosing a framework.
- Bugs and security issues in a framework can affect every application using that framework. Therefore it must be tested and patched separately or in addition to the final software product.