The UML Profile for Framework Architectures
5.2 A sample cookbook recipe
Reconsider the RoundingPolicy variation point realized through the Separation construction principle (Figure 5.2). It provides an abstract class RoundingPolicy together with three specific implementations of the hook method round() in subclasses. Let us assume this example is part of a framework and let us define a recipe for its adaptation. What is required for adapting the rounding variation point?
Figure 5.2. Keeping the rounding policy flexible by means of the Separation construction principle
If the framework provides all the required implementations of RoundingPolicy, an adaptation by composition is feasible. In this case, the application developer plugs an appropriate instance of a RoundingPolicy subclass into a CurrencyConvertor object. If the UML-F fixed tag is attached to the generalization, additional rounding policies cannot be defined.
If, instead, the framework does not provide a complete set of subclasses of the RoundingPolicy class, the generalization should be marked as adapt-static or adapt-dyn . The application developer can then use one of the predefined classes, but can also add specific ones. The cookbook recipe in Table 5.2 describes this straightforward adaptation.
Recipe 'CurrencyConverter: How to adapt the rounding behavior' | |
---|---|
Intent | To adapt the rounding behavior of a currency converter. |
Classes |
|
Steps to Apply |
|
Discussion | See discussion above. |
Figure 5.3 presents a sample adaptation. The tag adapt-static explicitly indicates that the application developer may add new classes. Furthermore, some existing classes (such as RPol10) have been omitted in the diagram instead, an application class RPolByBase has been added. The presentation tag is attached to that class to indicate that all methods and instance variables provided by it are shown. Class RPolByBase allows the definition of the rounding base dynamically, thus providing additional flexibility.
Figure 5.3. A sample adaptation following the cookbook recipe
The UML-F tags indicate that the rounding policy variation point is based on the Separation pattern. Thus, a generic recipe for the Separation pattern would usually suffice for adapting variation points that rely on that construction principle. If more specific recipes are required, they could build on generic recipes. Sections 5.3 5.5 introduce the generic recipes for the Unification and Separation construction principles and for the Composite pattern.[1] For understanding and adapting the Decorator and Chain of Responsibility patterns, we refer to the GoF pattern catalog (Gamma et al., 1995).
[1] As the Composite, Decorator, and Chain of Responsibility construction principles overlap with the GoF patterns, we use the term 'pattern' for them for example, Composite pattern instead of Composite constructure principle.
Generic recipes for the adaptation of UML-F annotated variation points allow an efficient definition of more elaborate recipes for patterns and framework variation points. More specific recipes, which rely on and build on the generic recipes, typically add domain or framework-dependent information such as default implementations for the variation points, possible side effects, relevant constraints, and related variation points.