



















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
An overview of behavioral design patterns covered in lecture 4 of the software engineering course at sharif university of technology. The lecture is delivered by raman ramsin and includes patterns such as interpreter, template method, chain of responsibility, command, iterator, and mediator.
Typology: Slides
1 / 27
This page cannot be seen from the preview
Don't miss anything!




















1
Sharif University of Technology
Given a language, define a representation for its
grammar along with an interpreter that uses the representationg^
g^
p^
p
Template Method:
Define the skeleton of an algorithm in an
operation, deferring some steps to subclasses; lets subclassesredefine certain steps of an algorithm without changing thealgorithm's structurealgorithm s structure.
2
Sharif University of Technology
With
t^
i l ti
l ti^
t^
d
^ M
With
out violating encapsulation, capture and
Observer:
Define a one to many dependency between objects
^ Observer:
Define
a one-to-many dependency between objects
State:
Allow an object to alter its behavior when its internal
^ State:
Allow
an object to alter its behavior when its internal
Strategy:
Define a family of algorithms, encapsulate each one,
Visitor:
Represent an operation to be performed on the elements of an object structure; lets you define a new
4
Sharif University of Technology
elements
of an object structure; lets you define a new operation without changing the classes of the elements.
Avoid coupling the sender of a request to its receiver by giving more Avoid coupling the sender of a request to its receiver by giving morethan one object a chance to handle the request. Chain the receivingobjects and pass the request along the chain until an object handles it.
5
the Chain of Responsibility pattern when
^ more than one object may handle a request, and the
j^
y^
q^
,
handler isn't known
a priori. The handler should be
ascertained automatically. you want to issue a request to one of several objectswithout specifying the receiver explicitly. the set of objects that can handle a request shouldbe specified dynamically.
7
Sharif University of Technology
8
Encapsulate a request as an object, thereby letting you parameterizeclients with different requests
queue or log requests
and support
clients with different requests, queue or log requests, and supportundoable operations.
10
Sharif University of Technology
11
parameterize objects by an action to perform. specify, queue, and execute requests at different times. support undo. The Command's Execute operation can storestate for reversing its effects in the command itself. TheCommand interface must have an added Unexecute operationthat reverses the effects of a previous Executethat reverses the effects of a previous Execute. support logging changes so that they can be reapplied in caseof a system crash (by augmenting the Command interface withload and store operations)load and store operations). structure a system around high-level operations built onprimitives operations (based on the commands' commoni^
f^
13
interface).
14
p
j
operation from the one that knows how to perform it
.
9 Commands are first-class objects
They can be
9 Commands are first class objects. They can bemanipulated and extended like any other object. 9 Y
bl
d^
i
i
9 You can assemble commands into a compositecommand. 9 It's easy to add new Commands, because you don'thave to change existing classes.Department of Computer Engineering
16
Sharif University of Technology
Provide a way to access the elements of an aggregate object Provide a way to access the elements of an aggregate objectsequentially without exposing its underlying representation.
17
th^
It^
t^
tt
ย^ U
se the Iterator pattern ^ to access an aggregate object's contents without exposing its
l internal representation. to support multiple traversals of aggregate objects to support multiple traversals of aggregate objects. to provide a uniform interface for traversing different to provide a uniform interface for traversing differentaggregate structures (that is, to support polymorphic iteration).
19
20