Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Walter Zimmer
Forschungszentrum Informatik, Bereich Programmstrukturen
Haid-und-Neu-Strasse 10-14, D-76131 Karlsruhe, Germany
email: zimmer@fzi.de
X can be
Observer Glue Visitor combined Iterator Command Chain of Resp. Bridge
with Y
Memento
Mediator Strategy Both use a level State
of indirection
Figure 1 The starting point: The overall structure of the design pattern catalogue
Relationships between Design Patterns 3
problem and solution aspects. The relationships address- on the most interesting ones. Interesting means here, that
ing implementation details played a minor role in this pa- we find it difficult to assign a particular relationship into
per. For this reason, they were removed in later figures exactly one of the categories, that we are not sure about the
(Figure 3 and Figure 4). meaning of the relationship at all, or we think that some
further explanation is useful.
Directions of relationships
X uses Y in its solution
The descriptions of the relationships in the catalogue do
not contain the direction of the relationships, which may In most cases, the assignment of relationships to this cate-
be unidirectional — backwards or forwards — or bidi- gory is clear. Perhaps it would make sense to split these re-
rectional. Once the category that the relationship belongs lationships further into “X must use Y” and “X might use
to, is known, the direction can be determined rather Y”, because this information indicates the strength of the
quickly. But if one is not sure about the category, then the relationship.
direction often remains unclear.
X is similar to Y
Strength of relationship
Abstract Factory, Prototype and Builder are similar in that
Is the given relationship quite strong (like between Ab- they all deal with object creation. Builder and Visitor are
stract Factory and Factory Method) or are the design pat- strategies. Both Glue and Mediator serve to decouple ob-
terns more loosely coupled (like Observer and Solitaire)? jects. In contrast to Proxy and Decorator which allow the
Some design patterns can stand almost alone, others client to attach additional properties dynamically to an ob-
make sense only in combination with certain other de- ject, Adapter primarily serves to provide a completely dif-
sign patterns. The assessment of this property is often ferent interface to an object.
subjective because it is based on experience in using and
State (Strategy) is rather loosely coupled with Bridge and
combining different design patterns. Strategy (Flyweight) as this relationship addresses the im-
plementation detail “level of indirection” (“passing of state
3.2 Categories of relationships to objects”).
We have classified relationships between the pairs (X,Y) X can be combined with Y
of design patterns into the following categories:
A Builder often produces Composite objects. A Factory
X uses Y in its solution Method is typically called in a Template Method.
Composite, Visitor, Iterator: Iterator traverses
When building a solution for the problem addressed by
X, one subproblem is similar to the problem addressed composite structures and Visitor centralizes operations on
object structures. Depending upon the necessary degree of
by Y. Therefore, the design pattern X uses the design pat-
tern Y in its solution. Thus, the solution of Y (e.g. class flexibility, one typically combines two or all three design
patterns (for instance Interpreter).
structures) represents one part of the solution of X.
Composite, Decorator: Composite and Decorator are
X is similar to Y often used together in applications, for example for visual
They address a similar kind of problem (not a similar objects in ET++, MacApp and Interviews [Wein88],
[App89], [Lint89]. There are also other kinds of relation-
kind of solution). In several cases, these similarities are
also expressed in the classification given in the cata- ships between them: when looking at the solution aspect,
Decorator can be seen as a degenerated Composite; when
logue, e.g. the catalogue classifies both Prototype and
Abstract Factory in the category “Object - Creational”. considering the problem aspect, they both support recur-
sively structured objects, whereby Decorator focuses on
X can be combined with Y attaching additional properties to objects. Thus, the design
patterns are somehow similar, but it difficult to state it more
A typical combination of design patterns is the combina- precisely. Therefore, we only insert a relationship of type
tion of X and Y (e.g. Iterators traverse Composite struc- “combined”, and neglect the other ones.
tures). In contrast to “X uses Y”, X does not use Y in its
solution (or vice versa). 3.4 Using the classification
3.3 Classification This section gives several possibilities for using the pre-
sented classification when working with design patterns.
Figure 2 shows how we have classified the relationships
depicted in Figure 1 into these categories. Instead of jus-
tifying the classifications of all relationships, we focus
Relationships between Design Patterns 4
Prototype Builder
Factory Method
Interpreter Decorator
Solitaire Template Method
Memento
X Y X is similar to Y
4.2 Other modifications view lists, array and tables as sets. Thus Adapters standard-
ize the interfaces of the different ConcreteImplementor
The organization of the relationships in different catego- classes (lists, array and tables) to the common Implementor
ries is sometimes difficult, because it partly depends interface in the Bridge pattern.
upon subjective criteria. The difference between “X may
use Y” or “X can be combined with Y” depends upon a Objectifier — Template Method
subjective assessment, whether the usage of Y is seen as As explained in description of Objectifier (see Appendix),
a central part of the solution of X, or if it is more a com- both patterns serve the similar purpose of varying behav-
bination of two autonomous design patterns. iour.
Furthermore, two design patterns might be related
in different ways; Decorator / Composite and Abstract
Factory / Prototype are pairs of design patterns, which The integration of all these modifications, as well as
can be combined, and are also similar. In our paper, each the addition of the Objectifier pattern, into Figure 2 results
relationship is assigned to the most adequate category. in Figure 3.
Factory Method
Figure 2 shows that Factory Method does not use Tem- 5. Layers of design patterns
plate Method, but it is often called in a Template Method,
i.e. Factory Method often plays the role of a primitive in
a Template Method. Thus, if an Abstract Factory uses
5.1 Arrangement in several layers
Factory Method in its solution, then it really uses the de-
Up to now, we have classified the relationships between the
sign pattern Template Method. Therefore, we do not con-
design patterns and modified some of them. As one can see
sider Factory Method as a real design pattern, but as a “X
in Figure 3, “X uses Y” is the most frequent relationship.
use Y” relationship between Abstract Factory and Tem-
plate Method. Figure 3 draws an “X use Y” arrow be- We therefore try to arrange the patters according to
tween these design patterns and annotates it with Factory this predominant relationship. The graph defined by the “X
Method. uses Y” relationship is acyclic. This property allows us to
arrange the design patterns straightforwardly in different
Adapter — Decorator, Proxy layers as shown in Figure 4.
Among other things the catalogue says “Decorator is dif- Thus we identify three semantically different layers:
ferent from an Adapter, because a Decorator only chang- • Basic design patterns and techniques.
es an object‘s properties and not its interface; an Adapter
• Design patterns for typical software problems.
will give an object a completely new interface.” We think
that this is a main difference, and that Adapter is quite • Design patterns specific to an application
different from both Decorator and Proxy. This relation- domain.
ship is therefore removed.
5.2 Basic design patterns and
Flyweight — Abstract Factory techniques
As the manager part of Flyweight is no intrinsic part of
the design pattern, we remove this relationship. This layer contains the design patterns, which are heavily
used in the design patterns of higher layers and in object-
Objectifier — Flyweight, State oriented systems in general. The two design patterns Ob-
jectifier and Composite seem to be the most important ones
The relationships from Strategy to other design patterns as they are used by eight, respectively three other design
are transformed in corresponding relationships to Objec- patterns.
tifier. As we neglect relationships addressing implemen-
tation details, we remove these relationships from The problems addressed by these design patterns oc-
Objectifier to Flyweight and State. But as explained in cur again and again when developing object-oriented sys-
the previous section about Objectifier, State uses Objec- tems. The design patterns are thus very general. When
tifier in its own solution. Therefore, a new relationship building a system, one would often look upon them more
between State and Objectifier is added. as basic design techniques than as patterns.The intentions
of these design patterns (see Table 1) are very general and
Adapter — Bridge applicable to a broad range of problems occurring in the de-
sign of object-oriented systems.
Bridge may use Adapter in its own solution. An example
for this is the data structure set: Adapters can be used to
Relationships between Design Patterns 6
Proxy
Prototype Builder
Factory Method
Decorator
Interpreter
Solitaire Template Method
Table 1 Basic design patterns with Although the general problem of parsing some input
their respective purposes often occurs, we consider Interpreter to be more specific.
Interpreter is used to parse simple languages. The cata-
We regard the problem addressed by Composite logue lists some of the known uses of Interpreter, e.g. pars-
(and Decorator, Proxy) as a bit more specific than the ing constraints and matching regular expressions.
problems addressed by the other patters of this layer. Compiler construction is the major application domain.
Therefore, we thought about moving Composite into the The current catalogue contains almost no application
next higher layer. But Composite is a basic design pat- specific design patterns. Most patterns are generic and ap-
Relationships between Design Patterns 7
Factory
Method
4. [Booc93] also mentions that design patterns are rang- This will enable us to evaluate the validity and usefulness
ing from idioms to frameworks. of the classification scheme and improve it accordingly.
In [Coad93b], several design patterns are combined
in an exemplary application, but the relationships are not
investigated any further. 8. References
[Alex77] C. Alexander, S. Ishikawa, and M. Silverstein. A Pat-
7. Conclusion tern Language. Oxford University Press, 1977.
[App89] Apple Computer, Cupertino, California. Inc. Macintosh
We have presented a classification of the relationships Programmers Workshop Pascal 3.0 Reference, 1989.
between design patterns, which led to a new design pat- [Beck93] K. Beck. Patterns and software development. Dr. Do-
tern and to an arrangement of the design patterns into dif- bbs Journal, 19(2):18–23, 1993.
ferent layers. These results partially stem from one of our [Beck94] K. Beck and R. Johnson. Patterns generate architecture.
former projects [Zimm94]. Although the design pattern In Proceedings of ECOOP’94, 1994. To appear.
approach and the excellent catalogue [Gamm94] have
[Booc93] G. Booch. Patterns. Object Magazine, 3(2), 1993.
proven effective in this project, the following issues
showed up: [Busc93] F. Buschmann. Rational architectures for object-orien-
ted software systems. Journal of Object-Oriented Pro-
• The design of important abstractions of the gramming, 6(5):30–41, September 1993.
application domain often requires the
[Casa92] Eduardo Casais, Michael Ranft, Bernhard Schiefer,
combination of several, interrelated design
Dietmar Theobald, and Walter Zimmer. Obst - an overview.
patterns.
Technical report, Forschungszentrum Informatik (FZI), Karls-
• Applying design patterns requires a fair ruhe, Germany, June 1992. FZI.039.1.
knowledge of both single design patterns
[Coad93a] P. Coad. Object-oriented patterns. Communications of
and their relationships. the ACM, 35(9):153–159, September 1993.
• Tool support is needed to apply design
[Coad93b] P. Coad. Patterns (workshop). In OOPSLA’92 Adden-
patterns to really large applications. dum to the Proceedings, volume 4 of OOPS Messenger, pages
Our results address these issues because they help in: 93–96, Vancouver, B.C., Canada, October 1993. OOPS Mes-
senger, ACM Press.
• understanding the often complex relation-
ships between design patterns; [Copl91] J. Coplien. Advanced C++: Programming Styles and
Idioms. Addison-Wesley, 1991.
• organizing existing design patterns, as well
as categorizing and describing new design [Copl94] J.O. Coplien. Generative pattern languages: An emer-
patterns; ging direction of software design. Technical report, 1994.
• comparing different collections of design [Gamm93] E. Gamma, R. Helm, R. Johnson, and J. Vlissides.
patterns; Design patterns: Abstraction and reuse in object-oriented de-
signs. In O. Nierstrasz, editor, Proceedings of ECOOP’93, pa-
• and in building CASE tools which support ges 406–431, Berlin, 1993. Springer-Verlag.
design patterns.
[Gamm94] E. Gamma, R. Helm, R. Johnson, and J. Vlissides.
Thus, the results are a step towards the develop- Design Pattern. Addison-Wesley, To Appear, 1994.
ment of a pattern language. We think that this will be
very valuable for the development of object-oriented [John91] Ralph E. Johnson and Vincent F. Russo. Reusing ob-
ject-oriented designs. Technical Report Technical Report
systems.
UIUCDCS 91–1696, University of Illinois, May, 1991.
We are continuing our work with design patterns by
[John92] R. Johnson. Documenting frameworks using patterns.
formalizing the semantics of the different kinds of In Proceedings of OOPSLA’92, volume 27 of ACM SIGPLAN
relationships and the different layers shown in Figure 4. Notices, pages 63–76, Vancouver, B.C., Canada, October 1992.
We are aiming at greater precision and a better semantic ACM Press.
definition. This is a prerequisite for defining a generally
[Lint89] M. Linton, John Vlissides, and P. Calder. Composing
accepted and usable classification scheme, which will
user interfaces with interviews. IEEE Computer, 22(2):8–22,
serve as a basis for further work. February 1989.
Many design patterns are being discovered and de- [Pree94] W. Pree. Meta-patterns: A means for describing the es-
scribed outside of those in [Gamm94], especially appli- sentials of reusable o-o design. In Proceedings of ECOOP’94,
cation specific design patterns. We will organize them 1994. To Appear.
and their relations in the given classification scheme. [Rumb91] J. Rumbaugh, M. Blaha, W. Premerlani, F.Eddy, and
Relationships between Design Patterns 9
W.Lorensen. Object-Oriented Modeling And Design. Pren- ple of Mapping1, you have a class Mapping representing
tice-Hall, Englewood Cliffs, New Jersey, 1991. the abstraction, and an abstract class MappingImpl, which
[Shaw91] M. Shaw. Heterogenous design idioms for software is the superclass for the concrete implementation classes
architecture. In Proceeding of the Sixth International Work- MappingList, MappingHash. Mapping maintains a refer-
shop on Software Specification and Design, Software Engi- ence to MappingImpl, and it delegates the requests to its
neering Notes, pages 158–165, Como, Italy, October 25-26 current implementation object.
1991. IEEE Computer Society.
[WB90] Rebecca J. Wirfs-Brock and Ralph E. Johnson. Sur- Mapping
veying current research in object-oriented design. CACM, impl
insert(Object)
33(9):105–123, September 1990. remove(Object)
[Wein88] André Weinand, Erich Gamma, and Rudolph Marty.
MappingImpl
ET++ – an object-oriented application framework in C++. In
Proceedings OOPSLA ’88, ACM SIGPLAN Notices, pages impl->insert (Object); insert(Object)
remove(Object)
46–57, November 1988. Published as Proceedings OOPSLA
’88, ACM SIGPLAN Notices, volume 23, number 11.
[Zimm94] Walter Zimmer. Experiences using design patterns
MappingHash MappingList
to reorganize an object-oriented application, July 1994. Po-
sition paper for the Pattern Workshop at ECOOP’94. insert(Object) insert(Object)
remove(Object) remove(Object)
Name Applicability
Objectifier Use the Objectifier pattern when
• Behaviour should be decoupled from classes
Intent in order to have independent behaviour
Objectify similar behaviour in additional classes, so objects which can be interchanged, saved,
that clients can vary such behaviour independently from modified, shared or invoked.
other behaviour, thus supporting variation-oriented de- • Run-time configuration of behaviour is
sign (see [Gamm93]). Instances from those classes rep- required.
resent behaviour or properties, but not concrete objects • There are several almost identical classes
from the real world. which differ only in one or a few methods.
Objectifying the different behaviour in
Motivation additional classes allows to unify the former
Objectifier is a very general design pattern to be applied classes in one common class, which can then
in a wide range of problems. The idea of objectifying be- be configured with a reference to the new,
haviour is used in a lot of other design patterns. In the fol- additional classes.
lowing, the usage of Objectifier is shown with an • There is a large amount of conditional code to
example, which represents a somewhat simpler variant select behaviour.
of the design pattern Bridge.
Participants
A frequent problem in design is the separation of an
abstraction from its implementation, and the interchange Client
of implementations. For example, a data type Mapping • has a reference to the Objectifier.
might provide different implementations for different
tasks due to reasons of efficiency. • can be configured with a concrete Objectifier
at run-time.
A common approach is to have an abstract class for
Objectifier
the data type Mapping with concrete subclasses Map-
pingList and MappingHash representing different imple-
mentations. This allows to interchange the
implementation at compile-time, but not at run-time. 1. The OMT Notation [Rumb91] is used in this dia-
gram. Italic letters indicate abstract classes and meth-
A more flexible approach is to objectify the varying ods. The method insert from Mapping is represented in
behaviour, i.e. to have independent implementation ob- pseudo-code. The attribute impl of Mapping is a refer-
jects which can be interchanged at run-time. In the exam- ence to MappingImpl.
Relationships between Design Patterns 10
• defines the common interface for the a hash implementation (or vice versa). This replacement is
different concrete Objectifiers. It may also triggered by the Mapping object itself, not by the user.
contain data or references to other objects Objectifier is also used in the solution of other design pat-
which are common to all concrete Objec-
terns. Therefore, one can find real examples of Objectifier
tifiers. by looking at the design patterns referenced in the “See Al-
so” section.
Collaborations
• A client may use Objectifier to delegate See Also
parts of its behaviour. The Objectifier
Although several design patterns contain the common idea
receives the information needed to fulfil its
of objectifying behaviour to solve a problem, their purpos-
task during its initialization, or the client
es and requirements are more specific than those of Objec-
passes the information as a parameter when
tifier. Therefore, Objectifier is rather a generalization of
calling the Objectifier. these patterns than a totally new design pattern. It removes
• A client can be configured with a concrete redundancies in the descriptions of other design patterns
Objectifier to adapt the behaviour to a
current situation. As a lot of other issues have to be addressed when
applying these related design patterns, we regard them as
Class Diagram independent design patterns, not only as specialized
variants of Objectifier. Table 2 contains related design
Client patterns with the corresponding behaviour to be objectified
ref Objectifier (and potentially varied).
OperationA()
OperationB()
Design
Objectified behaviour
pattern
ConcreteObjectifierA ConcreteObjectifierB
OperationA() OperationA() Bridge Implementation of some abstraction
OperationB() OperationB()
Builder Creation / Representation of objects
Consequences
Command Command dependent behaviour
• Encapsulation, Modularity: Behaviour is
objectified and encapsulated in classes. Iterator Traversal of object structures
• Configurability, Customizability: Clients of Observer Context dependent behaviour
Objectifier can change the concrete Objec-
tifier at run-time. State State dependent behaviour
• Extensibility, Single Point of Evolution: Strategy (Complex) Algorithm
New behaviour can be implemented by
adding a new class without affecting Visitor Type dependent behaviour (types of
existing classes. single objects in Compound structure)
• Efficiency Table 2 Design patterns with their objec-
— Loss of time and space by an additional tified behaviour
level of indirection.
— The client can dynamically select the Strategy: Objectifier differs from Strategy in objecti-
class which is most efficient according to fying behaviour in a broader sense and is not restricted to
the current situation. algorithms in the classic sense of “algorithms and data
structures”. Thus, Objectifier is more general than Strategy.
— Stateless Objectifiers (without attributes)
can be shared by different objects. Template Method: It has a similar intent as Objectifi-
er: the variation of some behaviour. A Template Method
Known Uses represents the principal structure of an algorithm or behav-
iour, whereby parts of it can be varied in subclasses by
The example of the data type Mapping (see Motivation (re)defining methods (primitives). In contrast to this, Ob-
section) is taken from the data structure library of OBST, jectifier puts only the variable parts in additional classes, so
an object-oriented database system [Casa92]. The type that these parts can be varied independently from other be-
of the current implementation object of a Mapping object haviour. One superclass defines the common interface, and
depends upon the current size; if the number of objects several subclasses implement the concrete behaviour in
managed by the Mapping object exceeds eight (or falls different ways.
below four), then the list implementation is replaced with