- Objects: the Traditional View and the New View
- Encapsulation: the Traditional View and the New View
- Find What Is Varying and Encapsulate It
- Commonality/Variability and Abstract Classes
- Summary
Commonality/Variability and Abstract Classes
Object-oriented design captures all three perspectives
Consider Figure 8-4. It shows the relationship between
Commonality/variability analysis
The conceptual, specification, and implementation perspectives
An abstract class, its interface, and its derived classes
Figure 8-4 The relationship between commonality/variability analysis, perspectives, and abstract classes.
As you can see in Figure 8-4, commonality analysis relates to the conceptual view of the problem domain and variability analysis relates to the implementation, that is, to specific cases.
Now, specification gives a better understanding of abstract classes
The specification perspective lies in the middle. Both commonality and variability are involved in this perspective. The specification describes how to communicate with a set of objects that are conceptually similar. Each of these objects represents a variation of the common concept. This specification becomes an abstract class or an interface at the implementation level.
In the new perspective of object-oriented design, I can now say the following:
Mapping with Abstract Classes |
Discussion |
Abstract class ν the central binding concept |
An abstract class represents the core concept that binds together all of the derivatives of the class. This core concept is what defines the commonality. |
Commonality ν which abstract classes to use |
The commonalities define the abstract classes I need to use. |
Variations ν derivation of an abstract class |
The variations identified within that commonality become derivations of the abstract classes. |
Specification ν interface for abstract class |
The interface for these classes corresponds to the specification level. |
This simplifies the design process of the classes into a two-step procedure:
When Defining . . . |
You Must Ask Yourself. . . |
An abstract class (commonality) |
What interface is needed to handle all of the responsibilities of this class? |
Derived classes |
Given this particular implementation (this variation), how can I implement it with the given specification? |
The relationship between the specification perspective and the conceptual perspective is this: It identifies the interface I need to use to handle all of the cases of this concept (that is, the commonality).
The relationship between the specification perspective and the implementation perspective is this: Given this specification, how can I implement this particular case (this variation)?