5.4 Recipe for adapting the Separation construction principle
Figure 5.5 shows the structure of the Separation construction principle and Table 5.4 describes the corresponding generic recipe.
Figure 5.5. The structure of the Separation construction principle
Table 5.4. Adaptation of a variation point based on the Separation construction principle
Recipe 'Generic adaptation for the Separation construction principle'
Intent
The recipe describes how to adapt a variation point that is designed according to the Separation construction principle. Framework-specific considerations are not provided here.
Classes
Sep T marks the class with the template method, which is indirectly modified.
Sep H indicates the corresponding hook class/interface that has to be overridden/implemented.
See Figure 5.5 for the UML-F class diagram.
Steps to Apply
Understand the template hook relationship and the consequence of separating these methods.
Determine when and where in the template method Sep t the hook Sep h is used. Is the hook used more than once?
What is the hook method's responsibility, and how do changes affect the template?
Is the hook method used by another method in Sep T , in Sep H , or outside?
How is the association between template and hook(s) established? Determine whether there is already a (sub)class of Sep H that provides the desired or a similar functionality. Could that be refined?
If not, define a new (sub)class that inherits from Sep H , or that implements it in the case where it is an interface.
Implement the hook method in the newly defined subclass, indicated by the Sep h tag providing the desired functionality.
Determine whether you can reuse the provided default implementation through calling the inherited method. This is only possible if the inherited method is not abstract.
Instantiate (i.e. create an instance of) the appropriate Sep H class and plug it into the Sep T instance for example, by invoking a defineH() method of a T object.
Discussion
The Sep-H class may provide a default implementation for the hook method Sep-h that could be reused through super() calls. Comparing the Separation with the Unification construction principles, it is apparent that the Separation's ability to dynamically replace hook objects increases flexibility but also introduces some overhead (see Chapter 4).