































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
GoF Structural Patterns, Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy, Raman Ramsin, Lecture Slides, Patterns in Software Engineering, Department of Computer Engineering, Sharif University of Technology, Iran.
Typology: Slides
1 / 39
This page cannot be seen from the preview
Don't miss anything!
































1
Adapter:
Convert the interface of a class into another interface
clients expect
Adapter lets classes work together that couldn't
clients expect. Adapter lets classes work together that couldn totherwise because of incompatible interfaces.
^
Object
Bridge:
Decouple an abstraction from its implementation so that the
Bridge:
Decouple
an abstraction from its implementation so that the
two can vary independently.
Composite:
Compose objects into tree structures to represent whole-
part hierarchies. Composite lets clients treat individual objects andcompositions of objects uniformlycompositions of objects uniformly.
Decorator:
Attach additional responsibilities to an object dynamically.
Façade:
Provide a unified interface to a set of interfaces in a
subsystemsubsystem.
Flyweight:
Use sharing to support large numbers of fine-grained
objects efficiently.
Proxy:
Provide a surrogate or placeholder for another object to
2
Proxy:
Provide
a surrogate or placeholder for another object to
control access to it.
^
you want to use an existing class, and its interface does not match theone you need.one you need.
^
you want to create a reusable class that cooperates with unrelated orunforeseen classes
that is
classes that don't necessarily have
unforeseen classes, that is, classes that don t necessarily havecompatible interfaces.( bj
t
d
t^
l )
d t
l^
i ti
b l
b t
(object adapter only) you need to use several existing subclasses, butit's impractical to adapt their interface by subclassing every one. Anobject adapter can adapt the interface of its parent class.
4
Sharif University of Technology
5
q^
p
to adapt a class and all its subclasses.
7
It will require
8
Sharif University of Technology
t t
id^
t bi di
b t
b t
ti
^
you want to avoid a permanent binding between an abstractionand its implementation; for example, when the implementationmust be selected or switched at run-time.
^
both the abstractions and their implementations should be
^
both the abstractions and their implementations should beextensible by subclassing; combine different abstractions andimplementations and extend them independently.
^
changes in the implementation of an abstraction should have
^
changes in the implementation of an abstraction should haveno impact on clients; that is, their code should not have to berecompiled.
^
(C++) you want to hide the implementation of an abstraction
^
(C++) you want to hide the implementation of an abstractioncompletely from clients. In C++ the representation of a class isvisible in the class interface.
^
you want to share an implementation among multiple objects
10
Sharif University of Technology
^
you
want to share an implementation among multiple objects and this fact should be hidden from the client.
11
^
Compose objects into tree structures to represent part-whole
^
Compose objects into tree structures to represent part wholehierarchies. Composite lets clients treat individual objects andcompositions of objects uniformly.
13
^
you want to represent whole-part- hierarchies of objects.
^
you want clients to be able to ignore the difference betweencompositions of objects and individual objects. Clients will treatall objects in the composite structure uniformly.all objects in the composite structure uniformly.
14
16
and this simplifies their code
individual objects uniformly, and this simplifies their code. 9
If you want a composite to have only certain components, you can'trely on the type system to enforce those constraints for you. You'llhave to use run-time checks instead.
17
Sharif University of Technology
19
^
to add responsibilities to individual objects dynamically andtransparently
that is
without affecting other objects
transparently, that is, without affecting other objects.
^
for responsibilities that can be withdrawn
^
for responsibilities that can be withdrawn.h
t^
i^
b^
b l
i^
i^
i^
ti^
l^ S
ti
^
when extension by subclassing is impractical. Sometimes alarge number of independent extensions are possible andwould produce an explosion of subclasses.
20
Sharif University of Technology