27
Behavioral Design Patterns Presented by:- Priyanka Pradhan M.tech(SE)

Behavioral pattern By:-Priyanka Pradhan

Embed Size (px)

DESCRIPTION

Behavioral pattern of design pattern(software architectture and disign pattern) By:-Priyanka Pradhan

Citation preview

Behavioral Design Patterns

Presented by:-Priyanka Pradhan

M.tech(SE)

CONTENT

1. Design patterns introduction2. Pattern categories

3. Addressing quality attribute

4. Properties these patterns provide5. Behavioral design patterns

6. Reference

Design Patterns Introduction

2.A technique to repeat designer success.

3.Borrowed from Civil and Electrical Engineering domains.

1.A (Problem, Solution) pair: “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem in such a way that you can use this solution a million times over, without ever doing it the same way twice”

Patterns

– Design Problem.– Solution.– Implementation details.

Reduce gap

Design Implementation

Designer

Programmer

Pattern Categories

Creational Patterns concern the process of object creation. Deal with initializing and configuring classes and objects

Structural Patterns concern with integration and composition of classes and objects. Deal with decoupling interface and implementation of classes and objects

Behavioral Patterns concern with class or object communication. Deal with dynamic interactions among societies of classes and objects. How they distribute responsibility

Behavioral Pattern

• Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects

• It describes not just patterns of object or classes but also the patterns of communication between them

• Behavioral class patterns use inheritance to distribute behavior between classes

Addressing Quality Attribute

• Modifiability• Exchangeability• Reusability• Extensibility• Maintainability.

Properties these patterns provide

More general code for better Reusability

Redundant code elimination for better Maintainability

Behavioral Design Patterns

• Interpreter• Iterator• Mediator• Observer• State• Chain of Responsibility• Command• Template

Design Purpose

Interpret expressions written in a formal grammar.

Design Pattern Summary

Represent the grammar using a

recursive design pattern form: Pass

interpretation to aggregated objects.

Interpreter

Contd…

• Interpreter represents grammar as a class hierarchy and implements an interpreter as an operation on instance of these classes

Design Purpose

Provide a way to access the elements of an

aggregate object sequentially without

exposing its underlying representation.

Design Pattern Summary

Encapsulate the iteration in a class pointing

(in effect) to an element of the aggregate.

Iterator

Design Purpose

Avoid references between dependent objects

Design Pattern Summary

Capture mutual behavior in a separate class

Mediator

Contd…

• A Group of peer objects cooperate to perform a task that no single object can carry out by itself. An important issue here is how peer objects know about each other

• Peer could maintain explicit references to each other, but that would increase their coupling

• The Mediator Pattern avoids this by introducing a mediator objects between peers

Design Purpose

Arrange for a set of objects to

be affected by a single object

Design Pattern Summary

The single object aggregates the set, calling a

method with a fixed name on each member

Observer

Contd…

• The Observer Pattern defines and maintains a dependency between the objects

• The classic example of Observer is in Model/View/Controller, where all views of the model are notified whenever the model’s state changes

Design Purpose

Cause an object to behave in a

manner determined by its state

Design Pattern Summary

Aggregate a state object

and delegate behavior to it

State

Contd…

• The State Pattern encapsulates the state of an object so that the object can change its behavior when its state object changes

Design Purpose

Allow a set of objects to service a request.

It presents clients with a simple interface

Design Pattern Summary

Link the objects in a chain via aggregation,

allowing each to perform some of the

responsibility, passing the request along

Chain of Responsibility

Contd…

• It lets you send requests to an object implicitly through a chain of candidate objects

• Any candidate may fulfill the request depending on run-time conditions

• The number of candidates is open-ended, and you can select which candidates participate in the run-time

Design Purpose

Increase flexibility in calling for a service

e.g., allow undo-able operations

Design Pattern Summary

Capture operations as classes

Command

Contd…

• The Command pattern encapsulates request in an object so that it can be passed as a parameter, stored on a history list, or manipulated in other ways

Design Purpose

Allow runtime variants on an algorithm

Design Pattern Summary

Express the basic algorithm in a base class,

using method calls where variation is required

Template

Contd…

• A Template method is an abstract definition of an algorithm

• It defines the algorithm step by step

Behavioral Design Patterns capture behavior among objects

• Interpreter handles expressions in grammars

• Iterator visits members of a collection in a sequential fashion

• Mediator captures behavior among peer objects without

building a dependency between the objects

• Observer updates objects affected by a single object

• State allows method behavior to depend on current status

• Chain of Responsibility allows a set of objects to provide

functionality collectively

• Command captures function flexibly (e.g. undo-able)

• Template captures basic algorithms, allowing variability

Summary of Behavioral Design Patterns

Web Resources

• http://home.earthlink.net/~huston2/dp/• http://www.dofactory.com/• http://hillside.net/patterns/• Java Enterprise Design Patterns

Thank you for ur attention

Questions?