Meta Patterns
Meta Patterns
Wolfgang Pree
1 Introduction
One of the principal goals of object-oriented software development is to improve the
reusability of software components. Increased reusability of software is considered as
crucial technical precondition to improve the overall software quality and reduce
production and maintenance costs.
Reuse of Single Components. Conventional function-/procedure libraries can
be viewed as sets of small building blocks that might be compared to elemenatry
components such as screws and bolts in the real world. Libraries that offer more
complex functions and procedures based on the ‘call-back’ principle (for example,
some libraries for GUI programming belong to that category) turned out to be often
too inflexible and too difficult to use.
Module-oriented languages such as Ada and Modula-2 allow to express the concept
of Abstract Data Types (ADTs). Unfortunatley, it is almost impossible to construct
such modules in a way so that they meet all future requirements no matter in which
project the modules will be reused. Typically, a small ‘delta’ has to be changed so that
a module can be reused in software projects other than the one it was originally
designed for.
Such variants of the original module are not compatible any more. Furthermore,
chances are high that these delta changes in the source code imply errors.
As a consequence, module-oriented programming could not lead to the awaited
breakthrough in software reusability. Only pretty simple modular components such as
linked lists, sets, hash tables, etc. are reusable in numerous projects without modifi-
cations.
Since object-oriented languages support that programming by difference this
problem is alleviated: ADTs can often be adapted without touching the source code of
the original ADT. The adapted ADTs are compatible to the original one.
Concepts offered by object-oriented programming languages are used in many
projects for the sole purpose of producing reusable single components.
Reuse of Architectures. The concepts inheritance and dynamic binding are
sufficient to construct so-called frameworks, that is, reusable semi-finished
architectures for various application domains. Such frameworks mean a real
breakthrough in software reusability: not only single building blocks but whole
software (sub-)systems including their design can be reused.
Though most of the matured framworks exist for the GUI domain (such as
MacApp [1], and ET++ [4, 9, 10]) the framework concept can be applied to any
application domain. The term application framework is often used for frameworks
which constitute a generic application for a domain area. We use the term framework
for both application framework and ‘small’ framework that might consist of a few
components and be part of an application framework. In cases where a distinction is
necessary the term application framework is explicitly used.
A pioneering work was accomplished by Erich Gamma in his doctoral thesis [4]
which describes design patterns in the ET++ application framework [9, 10]. The work
presented in this paper has been inspired by the OOPSLA’91 - OOPSLA’93
workshops and Erich Gamma’s design pattern descriptions.
Design Patterns and OOAD Methodologies. State-of-the-art OOAD method-
ologies such as the Object Model Technique (OMT) [8], Booch’s method [2] and the
Responsibility-Driven-Approach [12] are limited in that the development and
adaptation of frameworks are not primarily addressed. This is true for all of the
numerous OOAD methodologies. Though there are significant differences in the
applied notation, the methodologies themselves are not radically different. Rumbaugh
et al. [8] express this in the following way: ‘All of the object-oriented methodologies,
including ours, have much in common, and should be contrasted more with non-
object-oriented methodologies than with each other.’
OOAD methodologies assist in the development of a well-structured object-
oriented system. Frameworks have to evolve from this initial framework design.
Design patterns can support this architecture evolution. In that sense, OOAD
methodologies are complemented by design pattern approaches.
4 Meta Patterns
Framework-centered design pattern approaches, such as the design pattern catalog [5,
6] attempt to pick out framework examples that are not too domain-specific. Such
frameworks are presented as examples of good object-oriented design that can be
applied in the development of other frameworks. We use the term framework example
design patterns for those design patterns. Framework example design patterns mainly
differ in the semantic aspect of the hot spot that is kept flexible.
Since experienced object-oriented designers collected these framework example
design patterns we consider these catalogs as useful means to construct new
frameworks. Furthermore, framework example design patterns typically include
implementation hints. Nevertheless, we think that a more advanced abstraction is
helpful, for example, in order to actively support the design pattern idea in the realm
of tools.
We introduce the term meta patterns for a set of design patterns that describes how
to construct frameworks independent of a specific domain. Actually, it is pretty
straight-forward to construct frameworks by combining the basic object-oriented
concepts. Thus these meta patterns turn out to be an elegant and powerful approach
that can be applied to categorize and describe any framework example design pattern
on a meta-level. So meta patterns do not replace state-of-the-art design pattern
approaches but complement them.
The Object Model Notation proposed by Rumbaugh et al. [8] is used in order to
depict class and object diagrams.
M1()
B::M3() B::M1()
M2()
M3() B::M2()
Subclass B1 adapts the template method M1() by overriding M2(). Thus the hot spot
M2() is filled. The template method M1() of class B is adapted without changing its
source code as illustrated in Figure 3.
B1 B
M1()
B::M3() B::M1()
M2()
B1::M2()
M3()
Of course, method M3() can also be overridden in a subclass of B in order to adapt this
hot spot of template method M1().
Flexibility Across Class Borders. In general, methods of a class B establish a
contract—subclasses can only modify method implementations or add new methods.
Either methods of class B itself (as shown in the example above) or of any other class
can be based on the contract of B (‘based on the contract of B’ means that variables of
static type B are used and messages corresponding to the contract of B are sent to these
B objects). The following example illustrates the case that another class A is based on
the contract of B . Due to polymorphism, other components of the application
framework that are based on B , work with instances of any subclass of B . What
actually happens at run-time depends on the object’s run-time type, i.e., how the
particular hook methods are implemented in the corresponding subclasses of B. The
term abstract coupling is used to express that.
bRef
A B
... M1()
MethodOfA() M2()
...
M3()
...
if (...)
bRef->M1();
...
...
SpecB
M2()
H H
... ...
hRef hList
T T
thRef thList
TH TH
TH
Unification Pattern
(T)
(T) (T)
(H)
(H)
What is the purpose of the template method in the realm of the 1:N Recursive
Connection pattern?
Due to the structure of the template method shown in Figure 6 messages are
automatically forwarded along the objects in a directed graph. In general, a T object
can be viewed as a place holder for all objects following that T object in the directed
graph. Instead of sending the message TH to all these objects it is sufficient to send
the message to the particular T object. This message is then automatically forwarded
to the other objects that are placed ‘behind’ that T object in the directed graph.
Due to this forwarding property of typical template methods in recursive
connection patterns a hierachy of objects built by means of the 1:N Recursive
Connection pattern can be treated as a single object.
The structure of the other composition meta patterns and guidelines when to
choose them are discussed in detail in [7]. Composition meta patterns especially differ
in the offered degree of flexibility of the hot spots. For example, choosing the
Unification meta pattern implies the following: in order to change the template
method by providing a different hook method a subclass of the unified template-hook
class TH has to be defined. Thus changes of the template method cannot occur
dynamically at runtime.
More flexibility is provided if template and hook classes are separated. This means
that the behavior of a T object, i.e., its template method, can be changed by
associating a different H object with the T object. Creating H objects and assigning
references to T objects can be done at runtime.
H
TH()
hList
...
T
TH()
Item
...
GetSizeInBytes(): Integer
items
...
...
Folder
GetSizeInBytes(): Integer
...
Fig. 8. Attaching the 1:N Recursive Connection meta pattern to a sample framework
The semantic aspect of the hot spot in that sample framework is the way Item objects
calculate their size.
Due to the characteristics of the 1:N Recursive Connection pattern Folder objects
can be treated as single Item objects so that hierarchies can be composed. Requests
such as GetSizeInBytes are automatically forwarded within an object hierarchy
(assuming that the template method GetSizeInBytes adheres to the typical structure of
template methods in the 1:N Recursive Connection pattern). Furthermore, the
behavior that is kept flexible by means of this pattern, that is, the size calculation,
can be adapted at runtime—Folder objects calculate their size correctly if the contained
items are changed.
1:1 Connection Meta Pattern. For example, in the domain of reservation
systems the initial hot-spot analysis might reveal that the rate calculation has to
become one of the hot spots of an application framework for that domain. If the way
how rental rates are calculated for a rental item has to be kept flexible the 1:1
Connection meta pattern could be chosen in the framework design as shown in Figure
9.
hRef
T H
T() H()
calculator
RentalItem RateCalculator
... ...
PrintInvoice() CalcRate(^RentalItem): Real
... ...
...
...= calculator->CalcRate(this);
...
...
StdRC
...
CalcRate(^RentalItem): Real
...
So reservation systems built by adapting that framework have to specify the rate
calculation in a subclass of RateCalculator . For example, objects of a class
HotelRoom (as subclass of RentalItem) in a hotel reservation system will require a
different RateCalculator object than instances of a class Vehicle in a rental car
reservation system. Due to the characteristics of the 1:1 Connection meta pattern, the
rate calculation behavior can be switched at runtime by coupling a RentalItem object
with various RateCalculator objects—one at a time.
6 Summarizing Remarks and Outlook
The seven composition meta patterns repeatedly occur in frameworks. Each framework
uses, of course, specific names for the template and hook classes and the
corresponding methods, depending on the semantics of the hot spots and the white
spots. The core characteristics of the composition meta patterns are independent of
their particular application.
Thus, a hypertext design browser could be based on the meta pattern descriptions
to provide a means to browse through numerous examples where a composition meta
pattern is combined with domain-specific template and hook methods.
The fact that myriads of meta pattern annotations are possible in (application)
frameworks might be considered as disadvantage: almost each method calls other
methods and thus becomes a template method that is based on hook methods. Meta
patterns could be attached to all calls where a particular method is the template method
and the invoked methods are hook methods. Persons that know a framework well
enough, especially the developers of a framework can select those aspects that should
be put into a meta pattern browser.
Meta patterns are useful when they are attached to already matured frameworks. It
does not make sense to define meta pattern browsers for frameworks that are in their
early development stages, i.e., where it is still not clear whether template and hook
classes are defined and implemented according to the needs of the framework domain.
Meta pattern browsers for matured (application) frameworks can be viewed as
advanced design pattern catalogs. Some aspects of a specific framework might be
pretty domain-independent so that this design can be applied in the development of
new frameworks. In these cases meta pattern browsers serve the same purpose as
design pattern catalogs. Actually design pattern catalogs can be viewed as carefully
chosen subsets of the design examples that can be captured and categorized in meta
pattern browsers.
In addition to design pattern catalogs meta pattern browsers can instrument any
domain-specific framework and document its design. The aspect that meta pattern
browsers allow an efficient design documentation of frameworks can help in adapting
the hot spots of a framework to specific needs.
Future research based on a prototype implementation of a meta pattern browser
will reveal the suitability of a design documentation based on meta patterns for the
adaptation and development of frameworks.
References
1. Apple Computer: MacApp II Programmer’s Guide; 1989.
2. Booch G.: Object-Oriented Design; Redwood City, CA, Benjamin/Cummings,
1991.
3. Coad P.: Object-Oriented Patterns; in Communications of the ACM, Vol. 33,
No. 9, Sept. 1992.
4. Gamma E.: Objektorientierte Software-Entwicklung am Beispiel von ET++:
Klassenbibliothek, Werkzeuge, Design; doctoral thesis, University of Zürich,
1991; published by Springer Verlag, 1992.
5. Gamma E., Helm R., Johnson R., Vlissides J.: Design Patterns: Abstraction and
Reuse of Object-Oriented Design; in ECOOP’93 Conference Proceedings,
Springer Verlag, 1993.
6. Gamma E., Helm R., Johnson R., Vlissides J.: Design Patterns—
Microarchitecturs for Reusable Object-Oriented Software; Addison-Wesley, 1994.
7. Pree W.: Design Patterns for Object-Oriented Software Development;
(preliminary title) to be published by Addison-Wesley/ACM Press, 1994.
8. Rumbaugh J., Blaha M., Premerlani W., Eddy F., Lorensen W.: Object-Oriented
Modeling and Design; Prentice Hall, Englewood Cliffs, New Jersey, 1991.
9. Weinand A., Gamma E., Marty R.: ET++ - An Object-Oriented Application
Framework in C++; OOPSLA’88, Special Issue of SIGPLAN Notices, Vol. 23,
No. 11, 1988.
10. Weinand A., Gamma E., Marty R.: Design and Implementation of ET++, a
Seamless Object-Oriented Application Framework; in Structured Programming
Vol.10, No.2, Springer 1989.
11. Wirfs-Brock R.J., Johnson R.E.: Surveying Current Research in Object-Oriented
Design; in Communications of the ACM, Vol. 33, No. 9, 1990.
12. Wirfs-Brock R., Wilkerson B., Wiener L.: Designing Object-Oriented Software;
Prentice Hall, Englewood Cliffs, New Jersey, 1990.