- The Use of Components Today
- Limitation of Components
- Approaching a Solution
- Keeping Concerns Separate
1.3 Approaching a Solution
So, you find that even though components are excellent tools to structure a complex system in some hierarchical fashion, they are nevertheless insufficient. Components cannot keep crosscutting concerns separate all the way down to code. Adding a new concern (a set of requirements) to the system becomes very painful.
The search is on for a new kind of modularity, one that can keep crosscutting concerns separate throughout the life cycle of the module—from requirements to analysis, design, code, and test. To achieve this modularity, you must also have a corresponding way to integrate or compose the new modularity into a coherent whole to get executable code. The new modularity must also help you collect all work on a concern, not just the code, but requirements, analysis, design, implementation, and test for that concern.
To achieve this new modularity, you need two things: a concern separation technique and a concern composition technique.
Concern Separation Technique
In order to keep concerns separate, you must model and structure concerns. The use-case technique is quite helpful in modeling concerns during requirements and analysis. We discuss use-cases in greater detail in Chapter 3, "Today with Use-cases," and in further depth in Part 2 of the book. Separating peer use-cases is easy (that is how use-cases are normally defined). Separating extension use-cases requires new language constructs. On top of that, you also need techniques to preserve the separation during design and implementation.
Concern Composition Mechanism
At some point in time, you need to compose the concerns. This can happen during compile time, post-compilation time, or even during execution. Composing normal extensions is relatively easy, since all that is needed is some automated way to monitor the execution of the base and execute the extension when required.
Composing peer use-cases is much harder—you must deal with overlapping behavior, conflicts, and other problems. Thus, the early efforts have been to keep extensions separate. In the next section, we discuss some of these early efforts to highlight that crosscutting concerns is not a new problem. Keeping extensions separate is also not a technique that is invented only recently. But certainly, aspect orientation (which we discuss in Chapter 2, "Attacking the Problem with Aspects") provides an elegant solution and hence a renewed interest in the problem of dealing with crosscutting concerns. Another reason we highlight earlier works is to show that aspect thinking is very much in line with use-case thinking and, hence, use-case–driven development is a strong candidate for conducting aspect-oriented software development.
1.3.1 Early Support for Extensions
The idea of keeping extensions separate dates back a long way and appeared in a 1986 paper discussing "Language Support for Changeable Large Real-Time Systems" [Jacobson 1986]. Jacobson introduced several terms in that paper; see Figure 1-4. The original program, that is, the base, is termed an existion. The new functionalities to be added to the existion are termed extensions. Extensions are inserted at designated execution points in the existion. These execution points are known as extension points.
Figure 1-4 Existions, extension points, and extensions.
The key idea behind the approach is that you insert extensions into the existions during compilation or execution—not during coding. Thus, the source code of the existing system and even possibly its binaries remain clean and free of any extensions.
Structuring a system as shown in Figure 1-4 has several advantages. First, it makes extending an existing system a lot easier. When you want to introduce an extension, all you need to do is designate the extension point where the extension needs to be inserted. But this is no excuse for poor programming and design practices. Good development and programming practices make it easier for you to specify extension points.
Second, and even more fundamentally, structuring a system this way makes systems much more understandable. You structure the system from a base and then add more functionality in chunks that are not necessary to understanding the base. This allows our limited minds to focus on a particular concern at a time in isolation without the disturbance of other concerns. You can apply this approach to structure almost anything beyond codes. You can even apply it to requirement specifications and design.
How is support for extensions achieved? It can be achieved in several ways—during compilation time or runtime. One of the possible ways to do so during runtime is through a much earlier work by Jacobson. It is known as a sequence variator, and its operation is depicted in Figure 1-5 [Jacobson 1981].
Figure 1-5 Sequence variator.
The sequence variator works at microprogram level. The program consists of a list of statements, and each statement has a bit flag to indicate whether an extension occurs at that point. In typical operation, the sequence variation takes a statement from memory and executes it, then takes and executes the next statement, then the next, and so on. If the extension bit flag is set, the sequence variator looks for an extension that references the current statement and proceeds to execute the statements in the extension. When all the statements in the extension have been executed, the sequence variator resumes with the statement at the existion and continues.
From the existion programmer's viewpoint, you only view the statements, not the extension bit flag. When an extension must be added later on, all that is needed is to code the extension statements and turn on the appropriate extension bit flags in the existion. The existion programmer does not have to worry about extensions that are added later. You can easily add extension after extension without breaking the modularity of the existion. There is no tangling or scattering.
Jacobson filed a patent for this approach in 1981, but the patent was not accepted. The idea was too close to a patented patching technique for which his proposal would have been an infringement, so Jacobson always had to apologize for this closeness before explaining the idea.
A common fear about adopting aspect orientation is that practitioners feel that it is like patching. Definitely, if used in an ad hoc manner, it indeed is like patching. But aspect orientation is not for patching. It is for you to achieve better separation of crosscutting concerns. It is for you to achieve better modularity. The goal of this book is to provide you with sound techniques and practical guidelines to achieve this.
1.3.2 Support for Extensions in UML
Even though the patent was not accepted, the concept of keeping extensions separate persists. It manifests as extension use-cases, which made it to the Unified Modeling Language. In fact, for those of you who have applied use-cases, you should be quite familiar with the use-case extension concept. We go into the details later, but what we want to say is that the idea of keeping extensions separate is not new. Briefly, use-case extensions permit us to describe additional behaviors that can be inserted into an existing use-case. For example, you have an existing use-case called Reserve Room, and you want to add some waiting list functionality, as exemplified earlier. With the use-case modeling technique, you simply add an extension use-case, which is modeled as the Handle Waiting List use-case in Figure 1-6. In use-case modeling terminology, the Reserve Room use-case would be a base use-case, and the Handle Waiting List would be an extension use-case.
Figure 1-6 Waiting list as an extension use-case.
The use-case technique provides the means to specify how behaviors described in the extension use-case are inserted at the extension points defined in the base use-case.
Nevertheless, the idea of keeping extensions separate remains a specification technique as opposed to an implementation technique. In Object-Oriented Software Engineering [Jacobson et al. 1992], there are techniques to keep extensions separate during analysis and during use-case modeling. However, there are no techniques to keep extensions separate during design, since there was no aspect-oriented programming language available when the book was written. In Software Reuse [Jacobson 1997], the authors generalize the concept of extension points into variation points, and many of these ideas have been carried over to the Reusable Asset Specification (RAS).
The first serious attempt to implement extensions was done in the early 1990s at Ericsson in the development of a new generation of switches. The people who adopted extensions took them into a new development environment called Delos, which supported extensions all the way down to code. Nevertheless, support for extensions in mainstream programming languages did not appear until the advent of aspect orientation technologies.