Creating and Documenting a New Style
In Section 6.3, we discussed the need to define a new style when combining two or more existing styles and the result was expected to be of enduring value to the current or future projects. There are also other reasons to define new styles. Style catalogs are by their nature incomplete. They grow as practitioners discover new styles that solve new problems or solve old problems in new ways. An architect designing the software for a system is likely to realize that he or she has used a new style or made a new twist on an existing style. What are the obligations for documenting a new style?
In broad terms, documenting a new architectural style is done by writing a style guide specifying a vocabulary of designas a set of element and relationship typesand rules for how that vocabulary can be used as a set of topological and semantic constraints. A second way is to define one or more architectural patterns. This is usually done by defining parameterized architectural fragments, or templates, which can be instantiated by filling in the missing parts.
Existing style catalogs prescribe different ways to catalog a style, but four key decisions must be made and documented.
- Vocabulary: What are the types of elements in the style? What relationships do they have? What are their properties? What are the rules of composition that determine how the vocabulary can be used?
- Semantics: What computational model do these elements support?
- Analyses: What forms of analysis are supported by the style?
- Implementation: What are the implementation strategies that allow one to produce an executable system?
In this book, Chapters 2, 4, and 5 use a slightly different catalog approach geared to the documentation of views discussed in those styles. The vocabulary section became Elements, Relations, and Properties, a good match. Semantics and analyses are manifested in What It's For and Not For, with a passing mention of computational models. Implementation was omitted from our descriptions as being of little interest in this context; in its place, we added a section on notations for the style.
Usually, the answers to the questions imposed by the style guide are interdependent. The choice of element vocabulary and the required properties may be driven by the kinds of analysis that one wants to perform. For instance, queuing-theoretic analysis depends on the use of connectors that support asynchronous, buffered messages, together with properties that indicate buffering capacity, latencies, and so on. Implementation strategies may exploit the fact that the architecture satisfies certain topological constraints. For example, a linear pipeline of filters can be optimized by combining the functions performed by several filters into one larger equivalent filter.
Getting all this working together is not an easy proposition. Consequently, architects often use three techniques to develop new styles.
- Combining styles: An architect mixes and matches elements from several existing styles to produce a new one. For example, you might combine the features of a peer-to-peer style and a publish-subscribe style, so that components can either synchronously invoke other components' methods or asynchronously publish events. Combining styles has the advantage of reuse. However, one must be careful that the features of one style do not violate the semantic assumptions and constraints of another. Consider, for example, combining repository and a pipe-and-filter style. In the new style, filters can communicate via either pipes or a shared database. Unfortunately, doing this means that filters can no longer be treated as asynchronous processes, as they may need to synchronize on shared-data access. Is this a problem? It depends on the kinds of analyses that you intend to perform and the implementation techniques you intend to use.
- Style specialization: Refining an existing style can be done in several ways. You can provide a more detailed, domain-specific vocabulary. For example, you might define a new style by specializing pipes and filters for process control by adding a set of special filter types for monitoring the environment and regulating set points. You might add new constraints. For example, you might define topological constraints in the process control style to enforce a closed-loop organization of the filters. You might add new properties to enable new forms of analysis.
- Analysis-driven styles: Choose a style to permit a particular form of analysis. Suppose that you want to be able to analyze a system for a certain quality attribute. You have a queuing theory that can do this. This analytic framework makes certain assumptions about the elements and their interactions, such as independent processes with buffered message queues. Embody those assumptions in the definition of the style.