The State Design Pattern A behavioral design pattern. Shivraj Persaud

Slides:



Advertisements
Similar presentations
By : Atri Chatterjee Souvik Ghosh
Advertisements

GoF State Pattern Aaron Jacobs State(305) Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
Matt Klein 7/2/2009.  Intent  Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Matt Klein 7/6/2009.  Behavioral Pattern  Intent  Allow an object to alter its behavior when its internal state changes. The object will appear to.
Zahra Moslehi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design pattern Course Fall 2010.
Bridge The decoupling of abstraction and implementation.
Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Fall 2009ACS Ron McFadyen1 The context maintains an instance of a concrete state subclass State Pattern Each subclass (concrete state) implements.
Design Patterns I 1. Creational Pattern Singleton: intent and structure Ensure a class has one instance, and provide a global point of access to it 2.
June 26, Design Patterns  What is a Design Pattern -- Each pattern describes a problem which occurs over and over again in our environment, and.
Design Patterns David Talby. This Lecture Handle Synchronization & Events Observer Simplify Complex Interactions Mediator Change Behavior Dynamically.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Prototype Creational Design Pattern By Brian Cavanaugh September 22, 2003 Software, Design and Documentation.
Spring 2010ACS-3913 Ron McFadyen1 Duck Example Consider the text example (up to page 6). Each type of duck is a subclass of Duck Most subclasses implement.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
1 GoF Template Method (pp ) GoF Strategy (pp ) PH Single User Protection (pp ) Presentation by Julie Betlach 6/08/2009.
Case Studies on Design Patterns Design Refinements Examples.
Abstract Factory Design Pattern making abstract things.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
©Fraser Hutchinson & Cliff Green C++ Certificate Program C++ Intermediate Decorator, Strategy, State Patterns.
Y2 eProjects Session 4 – Advanced Topics. Objectives  Dynamic Models  Design Patterns (Optional)  Software testing (for S4) ACCP i7.1\Sem3_4\eProject\T4.
Strategy Design Patterns CS 590L - Sushil Puradkar.
Design Patterns
GoF Sections Design Problems and Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
Design Patterns By Mareck Kortylevitch and Piotreck Ratchinsky.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Stéphane Ducasse 1 Strategy.
STATE PATTERN Presented by Bharavi Mishra Bharavi Mishraise
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
CS 5150 Software Engineering Lecture 16 Program Design 3.
Patterns are Roles What patterns are and what not…
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
STRATEGY PATTERN By Michelle Johnson. BACKGROUND Behavioral Pattern Allow you to define a family of algorithms, encapsulate each one, and make them interchangeable.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
4/16/2018 Design Patterns David Talby.
Software Design Refinement Using Design Patterns
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Software Design Patterns
Factory Patterns 1.
Behavioral Design Patterns
Software Design and Architecture
Software Design and Architecture
State pattern – A logical ‘Finite State Machine’
Design Patterns with C# (and Food!)
State Design Pattern 1.
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Flyweight Pattern 1.
DESIGN PATTERNS : State Pattern
Structural Patterns: Adapter and Bridge
State Pattern By the Group of Four.
Strategy Design Pattern
Software Design Lecture : 28.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

The State Design Pattern A behavioral design pattern. Shivraj Persaud

State Design Pattern  Encapsulate states as concrete objects.  Abstract them into an abstract class.  The system contains a reference to an abstract state class, which can be any of the concrete state classes dynamically.

Example – TCPConnection class  A TCPConnection object can be in one of several different states, established, listening or closed.  The behavior of TCPConnection is different in each of these three states.

Abstract state class TCPConnection TCPState Open() Close() Acknowledge() Open() Close() Acknowledge() state->Open() TCPEstablished Open() Close() Acknowledge() TCPListenTCPClosed Open() Close() Acknowledge() Open() Close() Acknowledge()

 TCPConnection maintains a state object which is a subclass of TCPState.  When the connection changes state the TCPConnection object changes the state object it uses.

Applicatiblity- when to use the state design pattern  An object’s behavior depends on its state and changes its behavior at run-time.  Operations have large, multipart conditional statements that depend on the object’s state. The State pattern puts each branch of the conditional in a separate class.

UML Diagram of the State Design Pattern

Participants Context (TCPConnection) - defines the interface of interest to clients. - maintains an instance of a ConcreteState subclass that defines the current state.

State (TCPState) - defines an interface for encapsulating the behavior associated with a particular state of the Context. ConreteState Subclasses (TCPEstablished, TCPListen, TCPClosed) - each subclass implements a behavior associated with a state of the Context.

Collaborations Context delegates state-specific requests to the current ConcreteState object. A context may pass itself as an argument to the state object handling the request. This lets the state object access the context if necessary.

Context is the primary interface for clients. Clients can configure a context with State objects. Once a context is configured, its clients don’t have to deal with the State objects directly. Either Context or the ConcreteState subclasses can decide which state succeeds another and under what circumstances.

Consequences It localizes state-specific behavior and partitions behavior for different states. It makes state transitions explicit. State objects can be shared.

Related patterns  Flyweight