State pattern – A logical ‘Finite State Machine’

Slides:



Advertisements
Similar presentations
Auto-Generation of Test Cases for Infinite States Reactive Systems Based on Symbolic Execution and Formula Rewriting Donghuo Chen School of Computer Science.
Advertisements

By : Atri Chatterjee Souvik Ghosh
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.
A Brief Introduction. Acknowledgements  The material in this tutorial is based in part on: Concurrency: State Models & Java Programming, by Jeff Magee.
COP 3331 Object Oriented Analysis and Design Chapter 7 – Design by Abastraction Jean Muhammad.
Abstract Classes and Interfaces The objectives of this chapter are: To explore the concept of abstract classes To understand interfaces To understand the.
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.
Winter 2007SEG2101 Chapter 41 Chapter 4 SDL – Structure and Behavior.
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.
Programming Languages and Paradigms Object-Oriented Programming.
Case Studies on Design Patterns Design Refinements Examples.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
©Fraser Hutchinson & Cliff Green C++ Certificate Program C++ Intermediate Decorator, Strategy, State Patterns.
CDF Run Control Implementation Elliott McCrory BD/Proton Source/Linac & CDF September 18, 2001.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Autumn 2012UCN T&B - IT/Computer Science1 State Pattern Implementation of State Machines State Pattern.
Unit 1 INTRODUCTION TO MODELING AND CLASS MODEL Ref : L7-UML.PDF.
3-1 State Design Pattern C Sc 335 Rick Mercer. State Design Pattern State is one of the Behavioral patterns It is similar to Strategy Allows an object.
SWT - Diagrammatics Lecture 4/4 - Diagramming in OO Software Development - partB 4-May-2000.
Understanding and using patterns in software development EEL 6883 Software Engineering Vol. 1 Chapter 4 pp Presenter: Sorosh Olamaei.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
CSC 131 Fall 2006 Lecture # 6 Object-Oriented Concepts.
Abstraction ADTs, Information Hiding and Encapsulation.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
1 Enhancing Program Comprehension with recovered State Models Stéphane S. Somé Timothy C. Lethbridge SITE, University of Ottawa.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Design Patterns Introduction
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
STATE PATTERN Presented by Bharavi Mishra Bharavi Mishraise
Bridge Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Fusion Design Overview Object Interaction Graph Visibility Graph Class Descriptions Inheritance Graphs Fusion: Design The overall goal of Design is to.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
The State Design Pattern A behavioral design pattern. Shivraj Persaud
Layers Architecture Pattern Source: Pattern-Oriented Software Architecture, Vol. 1, Buschmann, et al.
Abstract Factory Pattern Jiaxin Wang CSPP Winter 2010.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
Dependency Injection with Guice Technion – Institute of Technology Author: Gal Lalouche - Technion 2016 ©
Industrial Group Project Introduction to Object Oriented Programming Adelina Basholli, February, 2016.
Object-Oriented Design
Web Design & Development Lecture 9
The Movement To Objects
Object-Oriented Analysis and Design
EKT 472: Object Oriented Programming
Software Design and Architecture
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
Polymorphism.
Packages, Interfaces & Exception Handling
Lecture 23 Polymorphism Richard Gesick.
Interface.
State Design Pattern 1.
Java Programming Language
Introduction to Behavioral Patterns (2)
Interfaces.
Behavioral Design Pattern
Interpreter Pattern.
BRIDGE PATTERN.
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
Java Inheritance.
DESIGN PATTERNS : State Pattern
Context Objects Evolution of object behavior Behavioral patterns
Lecture 8 Evolution of object behavior Behavioral patterns
Introduction to Requirements Modeling
2) For each of the finite state machines above, use the sets derived in part 1) to produce the following:   i.                  a set of sequences that.
Abstract Classes and Interfaces
Decorator Pattern.
Abstract Classes and Interfaces
Presentation transcript:

State pattern – A logical ‘Finite State Machine’ State - Design Pattern State pattern – A logical ‘Finite State Machine’

Introduction State pattern Intent For an abstraction that executes a finite state machine Intent To allow an object to alter its behavior when its internal state changes. The object appears to have changed its class

Details Implementing objects states using explicit classes Examples TCP_Connection Established, Listen, Closed Car_PowerBand In Powerband, Below PowerBand and Above PowerBand Implementing the state concept Constant identifiers and Conditional logic Define different State class for each logical state

Implementing the State pattern From the object collaboration angle Context object and the State object Context object An object going through the different states Context maintains an object reference to the state State All different states are ‘concrete classes’ inheriting from an ‘abstract state base class’ State classes implement the ‘handle()’ method which localizes actions to be taken on an event in the FSM

Details Working the State Pattern Benefits of the State pattern Client configures Context with initial state States take care of state transition and state specific actions to be performed Benefits of the State pattern Localization of State specific behavior Partition behavior for different states

The Car Example

Writing a generic State class abstract class State {     static State initialState;     static final State state1 = new State1();     static final State state2 = new State2();     protected State() {       if (initialState == null) initialState = this;     }     abstract void stateExit(StateOwner owner);     abstract void stateEnter(StateOwner owner);   }   

Writing a generic State class class State1 extends State {     void stateExit(StateOwner owner) {     }     void stateEnter(StateOwner owner) {     }   }   class State2 extends State {     void stateExit(StateOwner owner) {     }     void stateEnter(StateOwner owner) {     }   }

Conclusion State pattern For an abstraction that executes a finite state machine Relies heavily on the OO concept of dynamic binding / Abstract base classes