


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















1
Patterns in Software Engineering ā Lecture 2
Ā
program to an interface, not to an implementation.
favor composition over class inheritance.
p
find what varies and encapsulate it.
2
Patterns in Software Engineering ā Lecture 2
4
Patterns in Software Engineering ā Lecture 2
Class
F
t
M th
d
D fi
i t
f
f
ti
bj
t
b t l t
F
actory Method:
D
efine an interface for creating an object, but let
subclasses decide which class to instantiate. Factory method lets aclass defer instantiation to subclasses.
Ā
Object
Abstract Factory:
Provide an interface for creating families of
related or dependent objects without specifying their concrete class.
p
j^
p
y
g
Builder:
Separate the construction of a complex object from its
representation so that the same construction process can createdifferent representations.
Prototype:
Specify the kinds of objects to create using a prototypical
instance, and create new objects by copying this prototype.
Singleton:
Ensure a class only has one instance, and provide a global
point of access to it
5
Sharif University of Technology
point
of access to it.
Patterns in Software Engineering ā Lecture 2
Ā
l^
't
ti i
t
th
l^
f
bj
t
it
t
t
a class can't anticipate the class of objects it must create.
a class wants its subclasses to specify the objects it creates
a class wants its subclasses to specify the objects it creates.
classes delegate responsibility to one of several helper
classes delegate responsibility to one of several helpersubclasses, and you want to localize the knowledge of whichhelper subclass is the delegate.
7
Sharif University of Technology
Patterns in Software Engineering ā Lecture 2
8
Patterns in Software Engineering ā Lecture 2
id
i t
f
f
ti
f
ili
f
l t d
rovide an interface for creating families of related or dependent objects without specifying their concrete classes.
10
Sharif University of Technology
Patterns in Software Engineering ā Lecture 2
Ā
a system should be independent of how its products arecreated, composed, and represented.created, composed, and represented.
a system should be configured with one of multiple families ofproducts.
a family of related product objects is designed to be usedtogether, and you need to enforce this constraint.
you want to provide a class library of products
and you want
you want to provide a class library of products, and you wantto reveal just their interfaces, not their implementations.
11
Sharif University of Technology
Patterns in Software Engineering ā Lecture 2
Concrete classes are isolated
Concrete
classes are isolated. Clients manipulate
Exchanging product families is easy. Different product
g
g p
y
Consistency among products is promoted
Consistency among products is promoted.S
k
d
f
d
d ff
l^
S
upporting new kinds of products is difficult. The
13
Sharif University of Technology
Patterns in Software Engineering ā Lecture 2
Intent:
Separate the construction of a complex object from its representation
Separate the construction of a complex object from its representationso that the same construction process can create differentrepresentations.
14
Patterns in Software Engineering ā Lecture 2
16
Patterns in Software Engineering ā Lecture 2
17
Patterns in Software Engineering ā Lecture 2
Specify the kinds of objects to create using a prototypical
Specify the kinds of objects to create using a prototypicalinstance, and create new objects by copying this prototype.
19
Patterns in Software Engineering ā Lecture 2
the classes to instantiate are specified at run-time, forexample, by dynamic loading.
building a class hierarchy of factories that parallels the classhierarchy of products should be avoidedhierarchy of products should be avoided.
instances of a class can have one of only a few different
instances of a class can have one of only a few differentcombinations of state.
Ā
It may be more convenient to install a corresponding number ofprototypes and clone them rather than instantiating the class
ll
20
manually.