Reusable Design Patterns
The design patterns help to resolve recurrent problems in object
programming, in the form of micro-architectures. The main patterns
are described in the reference book :
- E. Gamma, R. Helm, R. Johnson et J. Vlissides, "Design
patterns: Elements of reusable object-oriented software",
Addison-Wesley Professional 1994.
In this page, we give the list of the models presented in the course
with UML diagrams or the corresponding classes in the Java API.
Iterator
- Intent : "Provide a way to
access the elements of an aggregate object sequentially
without exposing its underlying representation."
- Implementation in the Java API :
java.util.Iterator
Adapter
- Intent : "Convert the
interface of a class into another interface clients expect.
Adapter lets classes work together that couldn't otherwise
because of incompatible interfaces."
- There are two kinds of adapters : adapters for objects or
adapters for classes. The first uses delegation, the second
inheritance.
- The main avantage of object adapters is that they may adapt in
the same time both a class C and any subclass of C. The main
advantage of a class adapter is that an adapted object is also
an instance of the original class (C). Thus, any method applying
to an instance of C may be applied on its adapted version.
Decorator
- Intent : "Attach additional
responsibilities to an object dynamically. Decorators provide
a flexible alternative to subclassing for extending
functionality."
- Example in the Java API : the class
java.io.BufferedReader
is a decorator for instances of the interface java.io.Reader
.
Observer
- Intent : "Define a
one-to-many dependency between objects so that when one object
changes state, all its dependents are notified and updated
automatically."
- Implementation in the Java API :
java.util.Observer
and java.util.Observable