Frameworks

Besides the Java language, a world of Java frameworks exists. These frameworks can afford substantial improvements in programmer productivity and enhance the quality, performance, reliability, and interoperability of different Java applications. Fortunately, many of these popular and widely used frameworks are open source projects, so anyone can benefit from them if he can invest some time in learning when and how to use such frameworks. This article is the first in a series to highlight a list of major Java application frameworks to Gamelan.com readers.

What Is a Framework?

According to Erich Gamma [GAM95] a framework is: "A set of cooperative classes that makes up a reusable design for a specific class of software. A framework provides architecture guidance by partitioning the design into abstract classes and defining their responsibilities and collaborations. A developer customized the framework to a particular application by subclassing and composing instances of framework classes."

Figure 1 shows that a framework is a complete design of a target application domain where only a portion of this design is implemented and the interfaces to the missing parts are explicitly defined. Usually, the implemented part represents the common processes and functions required for this type of applications which is time consuming to be re-implemented each time you build an application belongs to that domain.

Frameworks and Other Reuse Techniques

"Unless you want to learn a new technology or programming language, don't start a program from scratch." Software developers usually build their applications not only upon their previous expertise but also upon their previous code in similar projects. The simplest reuse technique is the opportunistic reuse in which developers cut and paste code from existing projects to create new ones. On the other hand, systematic reuse techniques (e.g. class libraries, design patterns, and frameworks) allow developers to reuse successful software models, designs, and implementations that have already been developed and tested.

Frameworks and Class Libraries

Class libraries provide the developer with a group of classes and abstractions to inherit from or instantiate them. Unlike frameworks, class libraries are more general and are not tied to a specific application domain. For example, you can utilize a mathematical class library in a wide range of applications.

Frameworks use class libraries and extend their benefits in two ways:

By using a framework, you don't only instantiate and/or inherit from some classes but you also have an underlying architecture to adhere to.

Frameworks are active and exhibit "inversion of control" at run-time. Inversion of control, one of the primary benefits of frameworks, will be described later in this article.

Frameworks and Patterns

During the development process of complex software systems, developers may face some programming problems. Some of these problems repeatedly appear in their next software projects. Until mid-1990s, the solutions of these problems were located only in the minds of expert developers. This is not the ideal location. The documentation of these problems and their proven solution is now known as "design patterns." Patterns support the reuse of design expertise by articulating the static and dynamic aspects of successful solutions to problems that arise when building software in a particular context.

Patterns guide framework design and use. Patterns can be viewed as more abstract micro-architectural elements of frameworks that document and motivate the semantics of frameworks in an effective way.

Why Use a Framework?

Frameworks can improve the quality of the software, speed the development process, and reduce the development costs. Fayad et al. [FAY99] has listed the following four primary benefits of using frameworks:

Reusability. The stable interfaces that frameworks provide enhance reusability by defining generic components that can be reapplied to create new applications. Framework reusability leverages the domain knowledge and prior effort of experienced developers to avoid re-creating and re-validating common solutions to recurring application requirements and software design challenges. Reuse of framework components can yield substantial improvements in programmer productivity, as well as enhance the quality, performance, reliability, and interoperability of software.

Extensibility. A framework enhances extensibility by providing explicit hook methods that allow applications to extend their stable interfaces. Hook methods systematically decouple the stable interfaces and behaviors of an application domain from the variations required by instantiations of an application in a particular context. Framework extensibility is essential to ensure timely customization of new application services and features.

Inversion of control. The run-time architecture of a framework is characterized by an "inversion of control." This architecture enables canonical application processing steps to be customized by event handler objects that are invoked via the framework's reactive dispatching mechanism. When events occur, the framework's dispatcher reacts by invoking hook methods on pre-registered handler objects, which perform application-specific processing on the events. Inversion of control allows the framework (rather than each application) to determine which set of application-specific methods to invoke in response to external events.