You are on page 1of 12

Structural Patterns: concerned with how objects/classes

can be combined to form larger structures. Structural:


the composition of classes or objects.
1. Adapter: Match interfaces of different classes
2. Bridge: Separates an objects interface from its
implementation
3. Composite: A tree structure of simple and composite
objects
4. Decorator: Add responsibilities to objects dynamically
5. Faade: A single class that represents an entire
subsystem
6. Flyweight: A fine-grained instance used for efficient
sharing 7.Proxy: An object representing another object
1
1. Adapter(139)
It is a structural pattern design pattern with 139
catalog number and used for interface to an
object.
Match interfaces of different classes.
Convert the interface of a class into another
interface clients expect. Adapter lets classes
work together that couldn't otherwise because
of incompatible interfaces.
Adapter fills the gap between two interfaces.
Adapter match interfaces of different classes.
Adapter changes interface of legacy code so
client can use it. Adapter pattern describes
2
1. Pattern Name : Adapter(139)
2. Classification : Structural Patterns
3. Intent : Convert the interface of a class into
another interface clients expect. Match
interfaces of different classes.
4. Also Know As: Other well-known name is
Wrapper.
5. Motivation: Sometimes a toolkit class that's
designed for reuse isn't reusable only because
its interface doesn't match the domain-specific
interface an application requires.
3
4
6.Applicability: Use the Adapter pattern
when
You want to use an existing class.
You want to create a reusable class.
You need to use several existing subclasses.
7.Structure: Class and interaction diagrams.
A class adapter uses multiple inheritance to
adapt one interface to another.
5
An object adapter relies on object composition
6
8.Participants: Objects/classes and their
responsibilities.
Participants are Target (Shape),Client
(DrawingEditor) , Adaptee (TextView) and
Adapter (TextShape).
9. Collaborations: How participants
collaborate. Participants are Target
(Shape),Client (DrawingEditor) , Adaptee
(TextView) and Adapter (TextShape)
collaborate with Clients call operations on
an Adapter instance.
7
10. Consequences: Trade-offs and results.
Apts Adaptee to Target by committing to
a concrete Adapter class.
Lets a single Adapter work with many
Adaptees.
Makes it harder to override Adaptee
behavior.
How much adapting does Adapter do?
Pluggable adapters.
Using two-way adapters to provide
transparency.
8
11. Implementation: Here are other
implementation issues to consider:
1. Implementing class adapters in C++.
2. Pluggable adapters.
3. Using abstract operations.
4. Using delegate objects.
5. Parameterized adapters.
9
12. Sample Code: Programs in c++
class Shape
{
public:
Shape();
virtual void BoundingBox( Point&
bottomLeft, Point& topRight )
const;
virtual Manipulator*
CreateManipulator() const;
};
10
13. Known Uses: Examples of pattern in real
systems.
Defines an Interactor abstract class for
user interface elements such as scroll
bars, buttons, and menus.
Defines an object adapter called
GraphicBlock, a subclass of Interactor
that contains a Graphic instance.
Pluggable adapters are common in
ObjectWorks in Smalltalk.
11
14. Related Patterns: Related patterns are
Bridge (151) , Decorator (175) and Proxy
(207) defines a representative or surrogate
for another object and does not change its
interface.
12

You might also like