P.5. Viewtypes and Styles
P.5.1 Viewtypes
DEFINITION
A viewtype defines the element types and relationship types used to describe the architecture of a software system from a particular perspective. |
Although no fixed set of views is appropriate for every system, broad guidelines can help us gain a footing. Architects need to think about their software in three ways simultaneously:
- How it is structured as a set of implementation units
- How it is structured as a set of elements that have runtime behavior and interactions
- How it relates to nonsoftware structures in its environment
Each view we present in PartI falls into one of these three categories, which we call viewtypes. The three viewtypes are
- The module viewtype
- The component-and-connector (C&C) viewtype
- The allocation viewtype
Views in the module viewtypemodule views for shortdocument a system's principal units of implementation. Views in the C&C viewtypeC&C viewsdocument the system's units of execution. And views in the allocation viewtypeallocation viewsdocument the relationships between a system's software and its development and execution environments. A viewtype constrains the set of elements and relations that exist in its views.
P.5.2 Styles
Within the confines of a viewtype, recurring forms have been widely observed, even if written for completely different systems. These forms occur often enough that they are worth writing and learning about in their own right. Perhaps they have interesting properties not shared by others. Perhaps they represent a significant and oft-used variation of the viewtype. Our description of each viewtype includes a section on commonly occurring forms and variations. We call these architectural styles, or styles. Styles have implications for architectural documentation and deserve definition and discussion in their own right.
DEFINITION
An architectural style is a specialization of element and relation types, together with a set of constraints on how they can be used. |
A style defines a family of architectures that satisfy the constraints. Styles allow one to apply specialized design knowledge to a particular class of systems and to support that class of system design with style-specific tools, analysis, and implementations. The literature is replete with a number of styles, and most architects have a wide selection in their repertoires.
For example, we'll see that modules can be arranged into a useful configuration by restricting what each one is allowed to use. The result is a layered stylea member of the module viewtypethat imparts to systems that use it qualities of modifiability, portability, and the ability to quickly extract a useful subset. Different systems will have a different number of layers, different contents in each layer, and different rules for what each layer is allowed to use. However, the layered style is abstract with respect to these options and can be studied and analyzed without binding them.
For another example, we'll see that client-server is a common architectural style, a member of the component-and-connector viewtype. The elements in this style are clients, servers, and the protocol connectors that depict their interaction. When used in a system, the client-server style imparts desirable properties to the system, such as the ability to add clients with little effort. Different systems will have different protocols, different numbers of servers, and different numbers of clients each can support. However, the client-server style is abstract with respect to these options and can be studied and analyzed without binding them.
Some styles are applicable in every software system: decomposition, uses, deployment, and work assignment, for example. Other styles occur only in systems in which they were explicitly chosen and designed in by the architect: layered, communicating-processes, and client-server, for example.
Choosing a system style, whether covered in this book or somewhere else, imparts a documentation obligation to record the specializations and constraints that the style imposes and the properties that the style imparts to the system. We call this piece of documentation a style guide. The obligation to document a style can usually be discharged by citing a description of the style in the literature: this book, for example. If you invent your own style, however, you will need to write a style guide for it.
No system is built exclusively from a single style. On the contrary, every system can be seen to be an amalgamation of many different styles. Some occur in every system, but systems also exhibit a combination of "chosen" styles as well. This amalgamation can occur in several ways.
- Different "areas" of the system might exhibit different styles. For example, a system might use a pipe-and-filter style to process input data but route the result to a database that is accessed by many elements. This system would be a blend of a pipe-and-filter and shared-data styles. Documentation for this system would include (1) a pipe-and-filter view that showed one part of the system and (2) a shared-data view that showed the other part. In a case like this, one or more elements must occur in both views and have properties of both kinds of elements. (Otherwise, the two parts of the system could not communicate with each other.) These bridging elements provide the continuity of understanding from one view to the next. They likely have multiple interfaces, each providing the mechanisms for letting the element work with other elements in each of the views to which it belongs.
- An element playing a part in one style may itself be composed of elements arranged in another style. For example, a server in a client-server system might, unknown to the other servers or its own clients, be implemented using a pipe-and-filter style. Documentation for this system would include a client-server view showing the overall system, as well as a pipe-and-filter view documenting that server.
- Finally, the same system might simply be seen in different lights, as though you were looking at it through filtered glasses. A system featuring a database repository may be seen as embodying either a shared-data style or a client-server style. If the clients are independent processes, the system may be seen as embodying a communicating-processes style. The glasses you choose will determine the style that you "see."
In the last case, your choice of style-filtered glasses depends, once again, on the uses to which you and your stakeholders intend to put the documentation. For instance, if the shared-data style gives you all the analysis tools you need, you might choose it rather than the other two options. If you need the perspective afforded by more than one style, however, you have a choice. You can document the corresponding views separately, or you can combine them into a single view that is, roughly speaking, the union of what the separate views would be.
All three cases make clear the need to be able to document different parts of a system by using different views. That is, a view need not show the entire system.
P.5.3 Summary: Viewtypes, Styles, and Views
The three viewtypesmodule, C&C, and allocationrepresent the three perspectives that an architect must consider when designing a system: the system as units of implementation, the system as units of runtime execution, and the mapping from software elements to environmental structures. A viewtype restricts the element typesmodules in the module viewtype, for instanceand the corresponding relationship types.
But even within the confines of a viewtype, choices must be made: how the elements are restricted, how they relate to one another, and constraints on their use or configuration. A style is a specialization of a viewtype and reflects recurring patterns of interaction, independent of any particular system (FigureP.2).
Figure P.2. For each viewtype, we describe several styles. You can add to the set by creating your own style or adapting one from another source. And within the confines of a style, choices need to be made: how the element and relation types in a style are bound to elements and relations in a system. These are the views of your architecture.
Even within the confines of a style, choices need to be made: how the element and relation types in a style are bound to elements and relations in a system. In the context of viewtypes and styles, then, a view can now be seen as a style that is bound to a particular system. For example, Chapter 4 describes the publish-subscribe style in terms of loosely coupled components whose interfaces allow the reporting of events and subscription to events, but the description of the style in Chapter 4 is independent of any system. If you choose the publish-subscribe style as a design strategy for your system, you will produce a publish-subscribe view by naming the components and the events they report and to which they subscribe.