Behavioral Design Patterns in GoF - Lecture 4 by Raman Ramsin, Sharif Univ., Slides of Software Engineering

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

2011/2012

Uploaded on 02/19/2012

hester
hester ๐Ÿ‡ฎ๐Ÿ‡ท

4.5

(13)

84 documents

1 / 27

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Patterns in
Software Engineering
Software
Engineering
Lecturer: Raman Ramsin
Lecturer:
Raman
Ramsin
Lecture 4
GoF Design Patterns โ€“ Behavioral
Pt1
Department of Computer Engineering 1Sharif University of Technology
P
ar
t
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download Behavioral Design Patterns in GoF - Lecture 4 by Raman Ramsin, Sharif Univ. and more Slides Software Engineering in PDF only on Docsity!

Patterns inSoftware EngineeringSoftware Engineering Lecturer: Raman RamsinLecturer:

Raman Ramsin

Lecture 4 GoF Design Patterns โ€“ Behavioral

P^

t 1

1

Sharif University of Technology

Part 1

Patterns in Software Engineering โ€“ Lecture 4 GoF Behavioral Patterns โ€“ Class ย„ Class^

Interpreter:

Given a language, define a representation for its

grammar along with an interpreter that uses the representationg^

g^

p^

p

to interpret sentences in the language.

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

Patterns in Software Engineering โ€“ Lecture 4 GoF Behavioral Patterns โ€“ Object (Contd.) ย„ Object (Contd.)

M^

t^

With

t^

i l ti

l ti^

t^

d

^ M

emento:

With

out violating encapsulation, capture and

externalize an object's internal state so that the object can berestored to this state later.

Observer:

Define a one to many dependency between objects

^ Observer:

Define

a one-to-many dependency between objects

so that when one object changes state, all its dependents arenotified and updated automatically.

State:

Allow an object to alter its behavior when its internal

^ State:

Allow

an object to alter its behavior when its internal

state changes. The object will appear to change its class.

Strategy:

Define a family of algorithms, encapsulate each one,

and make them interchangeable; lets the algorithm varyand make them interchangeable; lets the algorithm varyindependently from clients that use it.

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.

Patterns in Software Engineering โ€“ Lecture 4 Chain of Responsibility ย„ Intent:^

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

Patterns in Software Engineering โ€“ Lecture 4 Chain of Responsibility: Applicability ย„ Use the Chain of Responsibility pattern whenย„ Use

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

Patterns in Software Engineering โ€“ Lecture 4 Chain of Responsibility: Structure

8

Patterns in Software Engineering โ€“ Lecture 4 Command ย„ Intent:^

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

Patterns in Software Engineering โ€“ Lecture 4 Command: Examples

11

Patterns in Software Engineering โ€“ Lecture 4 Command: Applicability ย„ Use the Command pattern when you want to^

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).

Patterns in Software Engineering โ€“ Lecture 4 Command: Structure

14

Patterns in Software Engineering โ€“ Lecture 4 Command: Consequences 9 Command decouples the object that invokes the

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

Patterns in Software Engineering โ€“ Lecture 4 Iterator ย„ Intent:^

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

Patterns in Software Engineering โ€“ Lecture 4 Iterator: Applicability^ U^

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

Patterns in Software Engineering โ€“ Lecture 4 Iterator: Structure

20