Pattern Implementations and Compound Patterns
We’ve talked a bit about both pattern specifications and pattern implementations. A benefit of being able to use a pattern implementation is that by automating the use of the pattern we speed up the application of the pattern and also ensure that the pattern is applied consistently. However, another benefit comes when we can combine the idea of using a pattern implementation along with the creation of Compound (also seen as Composite) Patterns.
The idea of a Compound Pattern is that we find that there is a set of patterns that are often applied together in combination – whereby this combination is itself a pattern (commonly recurring, proven, and applies within a specific context). We could create a pattern specification that details the Compound Pattern and stop there – however, we then depend on the Pattern User to ensure that not only do they recognize the opportunity to use the compound pattern – but also that they correctly apply each of the combined patterns. This places a high burden on the pattern user.
In contrast – if we take the next step and create a pattern implementation for the Compound Pattern – we greatly reduce the complexity of applying the pattern. The pattern implementation encapsulates a number of patterns – hiding unnecessary details. To that end – we find that many of the parameters/roles of the patterns within the compound can be shared or calculated and we end up requiring smaller number of user supplied values compared to applying each of the patterns separately.
Following on our discussion about modeling patterns – the following figures provide examples of how we can detail Compound Patterns. Figure 1 shows how we can use a simple class diagram to relate the patterns that comprise the Compound Pattern.
Figure 1 – Class Diagram that details the patterns that comprise the Subsystem Façade pattern
Figure 2 shows how we can use a composite structure diagram to illustrate the parameters required by the Compound Pattern as well as how these values are then used by the patterns found within the Compound Pattern.
Figure 2 – Depicts a composite structure diagram highlighting key aspects of the Subsystem Façade pattern