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.

Slides:



Advertisements
Similar presentations
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Advertisements

SE2811 Week 7, Class 2 The Gang of Four and more … Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
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.
Design Patterns for Object Oriented systems CSC 515 Ashwin Dandwate.
Design Patterns Yes, they are important Robert Cotton April 23, 2009.
What is the Chain? It’s a behavioral design pattern. It deals with how objects make requests and how they are handled.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Design Patterns CS is not simply about programming
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Adapters Presented By Zachary Dea. Definition A pattern found in class diagrams in which you are able to reuse an ‘adaptee’ class by providing a class,
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Builder A Creational Design Pattern A Presentation by Alex Bluhm And.
Design Patterns Alan Shalloway, James Trott, Design Patterns Explained, Addison-Wesley, Gamma, Helm, Johnson, Vlissides, Design Patterns, Elements.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
BTS430 Systems Analysis and Design using UML Design Patterns.
©Fraser Hutchinson & Cliff Green C++ Certificate Program C++ Intermediate Decorator, Strategy, State Patterns.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
CS 325: Software Engineering February 12, 2015 Applying Responsibility-Assignment Patterns Design Patterns Situation-Specific Patterns Responsibility-Assignment.
 How are you going to collaborate?  How are you going to divide up work?  How are you going to make sure that changes work with other people’s code?
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Strategy Design Patterns CS 590L - Sushil Puradkar.
....and other creepy things from John Vlissides The Visitor Pattern EXISTS! And its INTENT is to represent an operation to be performed on the elements.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
CS 590L – Distributed Component Architecture 02/20/2003Uttara Paingankar1 Design Patterns: Factory Method The factory method defines an interface for creating.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
An Introduction To Design Patterns Jean-Paul S. Boodhoo Independent Consultant
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Chain of Responsibility Behavioral Pattern. Defination Avoid coupling between the sender and receiver by giving more than one object a chance to handle.
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.
Game Programming Patterns From the book by Robert Nystrom
CS, AUHenrik Bærbak Christensen1 Compositional Design Principles The “GoF” principles Or Principles of Flexible Design.
The State Design Pattern A behavioral design pattern. Shivraj Persaud
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Software Design Patterns
MPCS – Advanced java Programming
Design Patterns Introduction
Behavioral Design Patterns
Software Design and Architecture
Flyweight Design Pattern
Presented by Igor Ivković
State Design Pattern 1.
Mediator Design Pattern (Behavioral)
DESIGN PATTERNS : State Pattern
Strategy Design Pattern
Introduction to Design Patterns
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Design Patterns (Gamma, Helm, Johnson, Vlissides)
Composite Design Pattern By Aravind Reddy Patlola.
Presented by Igor Ivković
Software Design Lecture : 27.
Software Design Lecture : 28.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

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.

Applicability An object’s behavior depends on its state, and it must change its behavior at run-time depending on that state. Operations have large, multipart conditional statements that depend on the object’s state. This state usually represented by one or more enumerated constants. The State pattern puts each branch of the conditional in a separate class. This lets you treat the object’s state as an object in its own right that can vary independently from other objects.

Structure

Participants Context  Defines the interface of interest to clients.  Maintains an instance of a ConcreteState subclass that defines the current state. State  Defines an interface for encapsulating the behavior associated with a particular state of the Context. ConcreteState subclasses  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 behaviore for different states. It makes state transitions explicit. State objects can be shared.

Possible Issues If there are many different states that all need to have transition functions to one another, the amount of transition code required could be massive. Switch(State) case A: … case B: … etc…

Known Uses and Related Patterns Popular interactive drawing programs use the State pattern to perform specific operations based on which State(tool) is selected. The Flyweight (195) pattern explains when and how State objects can be shared. State Objects are often Singletons(127).

References State Pattern Picture:  Design Patterns, Elements of Reusable Object-Oriented Software  Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides