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.
- An interface is a complete design,
- where only a portion is implemented,
- and the interfaces to the missing components are explicitly defined.
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:
Modularity. Frameworks enhance modularity by encapsulating volatile implementation details behind stable interfaces. Framework modularity helps improve software quality by localizing the impact of design and implementation changes. This localization reduces the effort required to understand and maintain existing software.
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.
When Should You Use a Framework?
Do you think that you can get the benefits of a framework with no cost? Even if the framework is freely distributed, you still have to pay, in terms of time and efforts, to learn how to use this framework.
Obviously, use a framework when the cost of learning it is lower than the cost of writing the code from scratch. Also, keep in mind that the cost of learning a framework is amortized every time you reuse this framework in a new application.
Are Frameworks Worth the Struggle?
The answer is “Yes.” I admit that learning how to use a framework is not an easy task. The bad news is that you need to practice building up to three applications using a framework to realize what this framework is capable of. The good news is that frameworks can help you save 10%–95%, depending on the type of framework used. Not only are frameworks worth the struggle of learning them; they also are worth a company’s struggle to develop them for reuse in its software products.
Frameworks are classified by their scope to:
- System infrastructure frameworks
- Middleware integration frameworks
- Enterprise application frameworks
Frameworks also may be classified by the techniques used to extend them to:
- Whitebox frameworks
- Blackbox frameworks
In this series, we suggest classifying frameworks according to their target application. Table 1 shows an extended list of Java frameworks. This list could be extended either by adding a new application category or by adding new frameworks to an existing category.
|Table 1: Java Frameworks
|Jade, JAF, ABLE
|Java logging framework, Log4J
|JUnit, Cactus, JFCUnit, Abbot, Hansel
|Struts, WebWork, SOFIA, Cocoon, JBoss, JOFFAD
|Java Collections, BSF, Joone, …
What Is Next?
This article is intended to be the first in a monthly series. The following articles will introduce at least a framework for each type of application in Table 1. The main objective of this series is to show how Java developers can use different open source Java frameworks for more programming productivity and enhanced software quality.
The author would like to thank Rosemarie Graham for suggesting the idea of this series.
About the Author
Yasser EL-Manzalawy has been a Java programmer and instructor since 1998. He is currently an assistant Lecturer at the Systems & Computers Engineering Department, AZHAR University, Cairo. His Ph.D. research project aims to extend the Java language for agent-based systems.
- [GAM95] E. Gamma, R. Helm, R. Johnson, and J. Vlissades. Design Patterns: Elements of Reusable Software Architecture. Addison-Wesley, 1995.
- [FAY99] M. Fayad, D. Schmidt, R. Johnson. Building Application Frameworks: OO Foundations of Framework Design. John Wiley and Sons, 1999.
- Frameworks, Frameworks, Everywhere…, by John Earles
- Component Framework Worth the Struggle, by John D. Williams
- “UI Frameworks and JavaServer Faces,” by Michael Nash
- Choose the best Java framework for your application, By Harshad Oak.