Software Design Refinement Using Design Patterns Part II The FSM and the StateChart Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and.

Slides:



Advertisements
Similar presentations
UML State Machine Diagrams and Modeling
Advertisements

Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Software Requirements Engineering
Classes & Objects Computer Science I Last updated 9/30/10.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB JavaForum.
2 Object-Oriented Analysis and Design with the Unified Process Objectives  Explain how statecharts can be used to describe system behaviors  Use statecharts.
Introduction To System Analysis and Design
7M701 1 Software Engineering Object-oriented Design Sommerville, Ian (2001) Software Engineering, 6 th edition: Chapter 12 )
Component-Level Design
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Software Engineering I Object-Oriented Design
©Ian Sommerville 2006Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
Software Engineering I Object-Oriented Design Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science.
UML Sequence Diagrams Eileen Kraemer CSE 335 Michigan State University.
Advanced Behavioral Modeling
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 10: Statecharts.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Introduction To System Analysis and design
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 7 Slide 1 System models l Abstract descriptions of systems whose requirements are being.
An Introduction to Software Architecture
1 Object-Oriented Modeling Using UML (2) CS 3331 Fall 2009.
Unified Modeling Language, Version 2.0
Introduction To System Analysis and Design
UML Diagrams: Class Diagrams The Static Analysis Model Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
UML Diagrams: Sequence Diagrams The Requirements Model, and The Dynamic Analysis Model Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical.
Design engineering Vilnius The goal of design engineering is to produce a model that exhibits: firmness – a program should not have bugs that inhibit.
Sequence & Statechart Diagrams Month Day, Year. Agenda Training Plan Overview Actors and Use Case Diagrams Sequence Diagrams Diagram Elements Evolution.
Sommerville 2004,Mejia-Alvarez 2009Software Engineering, 7th edition. Chapter 8 Slide 1 System models.
CSC480 Software Engineering Lecture 11 September 30, 2002.
Notes of Rational Related cyt. 2 Outline 3 Capturing business requirements using use cases Practical principles  Find the right boundaries for your.
Software Engineering Prof. Ing. Ivo Vondrak, CSc. Dept. of Computer Science Technical University of Ostrava
The Static Analysis Model Class Diagrams Prof. Hany H. Ammar, CSEE, WVU, and Dept. of Computer Science, Faculty of Computers and Information, Cairo University.
Design Analysis builds a logical model that delivers the functionality. Design fully specifies how this functionality will be delivered. Design looks from.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
What is Object-Oriented?  Organization of software as a collection of discreet objects that incorporate both data structure and behavior.
Software Design Refinement Using Design Patterns Part II The FSM and the StateChart Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and.
1 Class Diagrams. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are for visualizing, specifying and documenting.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
OBJECT ORIENTED AND FUNCTION ORIENTED DESIGN 1 Chapter 6.
Introduction to OOAD and the UML
12 Chapter 12: Advanced Topics in Object-Oriented Design Systems Analysis and Design in a Changing World, 3 rd Edition.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
The Requirements, Analysis, and Design, and Desgin Refiement Models
DESIGN OF SOFTWARE ARCHITECTURE
1 Unified Modeling Language, Version 2.0 Chapter 2.
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall Object-Oriented Systems Analysis and Design Using UML Systems Analysis and Design,
The Dynamic Analysis Model StateCharts Prof. Hany H. Ammar, CSEE, WVU, and Dept. of Computer Science, Faculty of Computers and Information, Cairo University.
Chapter 10 Software quality. This chapter discusses n Some important properties we want our system to have, specifically correctness and maintainability.
Basic Characteristics of Object-Oriented Systems
Design Patterns: MORE Examples
Software Design Refinement Using Design Patterns
UML Diagrams: Class Diagrams The Static Analysis Model
Instructor: Dr. Hany H. Ammar
Object Oriented Analysis and Design
Design and Implementation
Class Diagrams.
An Introduction to Software Architecture
Dynamic Modeling Lecture # 37.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
Introduction to Pattern Oriented Analysis and Design (POAD)
UML Diagrams: StateCharts The Dynamic Analysis Model
Introduction to OOAD and the UML
Presentation transcript:

Software Design Refinement Using Design Patterns Part II The FSM and the StateChart Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU

Outline n Review – The Requirements, Analysis, Design, and Design Refinement Models – Design refinement and Design Patterns – Examples of Design Patterns: The State Pattern n Finite State Machine Pattern Language Basic FSM, State-Driven Transitions Interface Organization, Layered Organization n A Pattern Language for StateCharts Basic StateCharts, Hierarchical Statechart Orthogonal Behavior

The Requirements, Analysis, Design, and Design Refinement Models Static Analysis Dynamic Analysis Functional/ Nonfunctional Requirements Use Case Diagrams/ Sequence Diagrams (the system level) - Analysis Class Diagrams - State Diagrams/ Refined Sequence Diagrams (The object level) Requirements Elicitation Process The Analysis Process Static Architectural Design Dynamic Design The Design Process: Initial Design Design Refinement Design Class Diagrams Design Sequence Diagrams Design Refinement Refined Design Class Diagrams

Design Refinement n It is difficult to obtain a quality design from the initial design n The initial design is refined to enhance design quality using the software design criteria of modularity, information hiding, complexity, testability, and reusability. n New components (or new classes) are defined and existing components (or classes) structures are refined to enhance design quality n The design refinement step is an essential step before implementation and testing.

Class Diagram Refinement Using Design Patterns n Design Class Diagrams are further refined to enhance design quality (i.e., reduce coupling, increase cohesion, and reduce component complexity) using design patterns n A design pattern is a documented good design solution of a design problem n Repositories of design patterns were developed for many application domains (communication software, agent-based systems, web applications) n Many generic design patterns were defined and can be used to enhance the design of systems in different application domains

What is a Design Pattern n What is a Design Pattern? A design pattern describes a design problem which repeatedly occurred in previous designs, and then describes the core of the solution to that problem n Solutions are expressed in terms of classes of objects and interfaces (object-oriented design patterns) n A design pattern names, abstracts, and identifies the key aspects of a high quality design structure that make it useful for creating reusable object- oriented designs

Recall Examples of Design Patterns The State Pattern (Examples of State and Strategy Patterns) (Examples of State and Strategy Patterns) The State Pattern: is a solution to the problem of how to make the behavior of an object depend on its state.

Examples of Design Patterns The State Pattern n The State Pattern can be used for example to encapsulate the states of a controller as objects MultiStateOb +CreateInitState() Setstate() > State state ConcreteState 1 concreteState n Handel(), Oprn() Handle() Opr1(),Opr2() 1.. N …………….. N concrete state classes Abstract State Class Lets a mutli state class divide its responsibilities (Opr1(),Opr2(), and Oprn() on multiple state classes. The Context Class For more Info, see ~huston2/dp/state.html Current State Handle(), Context class

Example: Turn style coin machine The machine starts in a locked state (Locked). When a coin is detected (Coin), the machine changes to the unlocked state (UnLocked) and open the turnstyle gate for the person to pass. When the machine detects that a person has passed (Pass) it turns back to the locked state. Fixed/Inorder Failed/OutofOrder & Locked BrokenLocked Unlocked Failed/OutofOrder Coin[Amount>=CorrectAmount]/Unlock Coin/ThankYou Coin[Amount< CorrectAmount] Pass/Lock

Illustrating Example: Turn style coin machine n If a person attempts to pass while the machine is locked, an alarm is generated. n If a coin is inserted while the machine is unlocked, a Thankyou message is displayed. n When the machine fails to open or close the gate, a failure event (Failed) is generated and the machine enters the broken state (Broken). n When the repair person fixes the machine, the fixed event (Fixed) is generated and the machine returns to the locked state.

Outline n Review – The Requirements, Analysis, Design, and Design Refinement Models – Design refinement and Design Patterns – Examples of Design Patterns: The State Pattern n Finite State Machine Pattern Language Basic FSM, State-Driven Transitions Interface Organization, Layered Organization n A Pattern Language for StateCharts Basic StateCharts, Hierarchical Statechart Orthogonal Behavior

FSM Pattern Language (FSM Pattern: Yacoub PhD Dissertation, Ch. 10, WVU, 1999) Finite State Machine Patterns; European Pattern Languages of Programming conference, EuroPLoP (1998) Yacoub PhD Dissertation, Ch. 10, WVU, 1999) n FSM pattern language addresses several recurring design problems in implementing a finite state machine specification in an object-oriented design. n The pattern language includes a basic design pattern for FSMs whose design evolves from the GOF State pattern. n The basic pattern is extended to support solutions for other design problems that commonly challenge system designers. n These design decisions include state-transition mechanisms, design structure

Pattern Language of Finite State Machines (FSM Pattern:

FSM Pattern Language Pattern NameProblemSolution State Object (GoF State Pattern) How can you get different behavior from an entity if it differs according to the entity's state? Create states classes for the entity, describe its behavior in each state, attach a state to the entity, and delegate the action from the entity to its current state. EventsBasic FSMYour entity's state changes according to events in the system. The state transitions are determined from the entity specification. How can you implement the entity behavior in your design? Use the State Object pattern and add state transition mechanisms in response to state transition events. FSM pattern = State Object pattern + State Transition Mechanism State- Transitio n State-Driven Transitions How would you implement the state transition logic but yet keep the entity class simple? Have the states of the entity initiate the transition from self to the new state in response to the state- transition event. Owner-Driven Transitions You want your states to be simple and shareable with other entities, and you want the entity to have control on its current state. How can you achieve this? Make the entity respond to the events causing the state transitions and encapsulate the transition logic in the entity StructureLayered Organiza- tion You are using an FSM pattern, how can you make your design maintainable, easily readable, and eligible for reuse? Organize your design in a layered structure that decouples the logic of state transition from the entity's behavior, which is defined by actions and events Interface Organiza- tion How can other application entities communicate and interface to an entity whose behavior is described by an FSM? Encapsulate the states classes and state transition logic inside the machine and provide a simple interface to other application entities that receive events and dispatch them to the current state.

FSM Pattern Language (cont.) Machine Type Actions or outputs MeallyHow do you activate the FSM outputs if they should be produced at specific events while the entity is in a particular state? Make the concrete event method of each state call the required (output) action method in response to the event. MooreHow do you activate the FSM outputs if they are produced only at the state and each state has a specific set of outputs? Implement an output method in each state that calls the required actions. Make the state transition mechanism call the output method of the next upcoming state. HybridWhat do you do if some FSM outputs are activated on events and some other outputs are activated as the result of being in a particular state only? Make the event method of each state produce the event-dependent outputs, and make the state transition mechanism call an output method of the upcoming state to produce the state- dependent output. ExposureExposed StateYou want to allow other external entities in your application to know of your entity's state and have access to call some of the state's methods. Provide a method that exposes the state of the entity and allows access to the current state. Encapsulated State Your FSM should follow a sequence of state changes that should not be changed by other application entities. How can you ensure that no state changes are enforced to your entity? Encapsulate the current state inside the entity itself and keep the state reference as a private attribute. Only the entity itself can change its state by handling the events causing the state change but still delegate the behavior implementation to the current state. State Instantiatio n Static State Instantiatio n Your application is small and it has few states. Speed is a critical issue in state transitions. How do you instantiate your entity's states? Create instances of all possible states on the entity instantiation. Switch from current to next state by altering the reference to the next state Dynamic State Instantiatio n Your application is large and you have too many states. How do you instantiate the states in your application? Don’t initially create all states; make each state knowledgeable of the next upcoming states. Create instances of upcoming states on state entry and delete them on state exit.

Pattern Language of Finite State Machines (FSM Pattern:

The Basic FSM Pattern Structure n Context: Your application contains an entity whose behavior depends on its state. The entity's state changes according to events in the system, and the state transitions are determined from the entity specification. n Problem; How can you implement the behavior of the entity in your design? n Solution: Implement Event methods in each state class

The coin machine design using the Basic FSM pattern ()

Pattern Language of Finite State Machines (FSM Pattern:

The State-Driven Transitions Pattern (extends Basic FSM) n Problem: How would you implement the state transition logic but yet keep the entity class simple? n Solution: – Delegates the state transition logic to the state classes, make each state knowledgeable of the next upcoming state, and have the concrete states of the entity initiate the transition from self to the new state. – Use the pointer to self NextStates in the abstract class AState to provide generic pointers to upcoming states.

The structure of the State-Driven Transitions pattern (extends Basic FSM) n Context You are using the Basic FSM. You need to specify a state transition mechanism to complete the entity's behavior implementation of the Basic FSM. n Problem How would you implement the state transition logic but yet keep the entity class simple?

The coin machine design using State-Driven Transitions pattern

Pattern Language of Finite State Machines (FSM Pattern:

The Interface Organization pattern n Context: You are using the Basic FSM to implement the behavior of an entity n Problem: How can other application entities communicate and interface to your entity? n Solution: – Encapsulate the transition logic in the states and hide it from the entity interface i.e., use a state-driven transition mechanism. – Design the FSM to distinguish the interface that receives events and the states that handle events, invoke actions, and maintain the correct current state of the entity.

The structure of the Interface Organization pattern n Context You are using the Basic FSM to implement the behavior of an entity n Problem How can other application entities communicate and interface to your entity?

The coin machine design using the Interface Organization pattern

Pattern Language of Finite State Machines (FSM Pattern:

The Layered Organization Pattern n Context: You are using the Basic FSM to implement the behavior of an entity n Problem: How can you make your design maintainable, easily readable, and eligible for reuse? n Solution Organize your design in a layered structure that decouples the logic of state transitions from the entity's behavior as it is defined by actions and events.

The structure of the Layered Organization Pattern

The coin machine design using the Layered Organization Pattern

Outline n Review – The Requirements, Analysis, Design, and Design Refinement Models – Design refinement and Design Patterns – Examples of Design Patterns: The State Pattern n Finite State Machine Pattern Language Basic FSM, State-Driven Transitions Interface Organization, Layered Organization n A Pattern Language for StateCharts Basic StateCharts, Hierarchical Statechart Orthogonal Behavior

A Pattern Language for StateCharts Yacoub-Ammar paper, In Pattern Languages of Programs (PLOP 1998) Yacoub PhD Dissertation, Ch. 11, WVU, 1999) Yacoub-Ammar paper Yacoub PhD Dissertation, Ch. 11, WVU, 1999) State State Transition Mechanism Finite State Machines Basic Statechart Hierarchical Statechart Orthogonal Behavior Broadcasting History State Basic Statechart Specification Using Hierarchical States Superstates with history property Exercise independent behavior at the same time Broadcast events to orthogonal states StateChart Patterns Roadmap

A Pattern Language for StateCharts Pattern NameProblemSolution Basic StatechartYour application contains an entity whose behavior depends on its state. You have decided to use statechart's specifications to specify the entity's behavior. How do you implement the statechart specification into design? Use an object oriented design that encapsulates the state of the entity into separate classes that correspond to the states defined in the specification. Distinguish the events, conditions, actions, entry and exit activities in each state class as methods and attributes of the state classes. Hierarchical Statechart You are using the Basic Statechart. The application is large and your states seem to have a hierarchical nature. How do you implement the states hierarchy in your design? Use superstates classes that are inherited from the abstract state class. Use the Composite pattern [Gamma+95] to allow the superstate to contain other states. Keep the superstate knowledgeable of the current active state and dispatch events to it. Orthogonal Behavior You are using the Hierarchical Statechart. Your entity has several independent behaviors that it exercises at the same time. How do you deploy the entity's orthogonal behaviors in your design? Identify the superstates that run independently in your specification, then define a "Virtual superstate" as a collection of superstates that process the same events, dispatch the events to each state. BroadcastingYou are using the Orthogonal Behavior. How can you broadcast a stimulated event produced from another event occurring in an orthogonal state? When a new event is stimulated, make the broadcasting state inject the event directly to the entity interface which dispatches it to the virtual superstate. Eventually, the virtual supertate dispatches the event to all of its orthogonal states. History StateIf one of the superstates has a history property, how do you keep its history in your design? Initialize the current active state class pointer of the superstate object once on creation, use it throughout the entity's lifetime, and do not reinitialize it on the superstate entry method.

A Pattern Language for StateCharts: Basic StateCharts Pattern n Context Your application contains an entity whose behavior depends on its state. You are using a statechart to specify the entity's behavior n Problem How do you implement the statechart specification into design? n Solution: define a state class for each entity's state defined in the specification. Distinguish the events, conditions, actions, entry and exit procedures in each state class using FSM pattern language.

The structure of the Basic Statechart pattern Actions Events State1 Conditions entry () exit () Condition_Evaluation State2 Conditions entry () exit () Condition_Evaluation Entity_State Entity_Interface Entity_State : AState* Event_Dispatcher (Event) UpdateState(New_State : AState*) AState $ Entity_Ref : Entity_Interface * Num_States : int NextStates : AState** $ Conditions set_entity_state (New_State : AState*) exit() entry () ** Entity_Ref NextStates Event1() Action1() Event1() Event2()

The turn style coin machine specification extended Fixed/Inorder Failed/OutofOrder & Locked BrokenLocked Unlocked Failed/OutofOrder Coin[Amount>=CorrectAmount]/Unlock Coin/ThankYou Coin[Amount< CorrectAmount] Pass/Lock Locked Entry : Massage:InsertCoin On Coin : Accumulate Exit : Amount=0

The turn style coin machine specification extended n Implement the entry and exit specification as methods in each state class. n For example, the coin machine should keep track of the amount of coins inserted. So, in the Locked state the machine keeps counting the amount inserted using Accumulate() method. n On entering the Locked state the machine displays a message telling the user to insert coins to pass, thus on the entry() method the message is displayed. n Each time the machine leaves the lock state it should clear the amount of accumulated amount to zero, thus the exit() method clears the amount.

The coin machine design using the Basic Statechart Pattern Actions Lock () Unlock () Alarm () Thankyou () Outoforder () Inorder () Events Pass () Coin () Failed () Fixed () Broken Fixed () entry () Locked Accumulate() exit () entry () Pass () Unlocked Pass() Coin () entry () Entity_Ref NextStates * Machine_State CoinMachine_Interface Machine_State : AState* Event_Dispatcher (Event) UpdateState (New_State :AState*) AState $ Entity_Ref : CoinMachine_Interface* Num_States : int NextStates : AState** set_entity_state (New_State :AState*) entry() * exit()

A Pattern Language for StateCharts StateChart Patterns Roadmap State State Transition Mechanism Finite State Machines Basic Statechart Hierarchical Statechart Orthogonal Behavior Broadcasting History State Basic Statechart Specification Using Hierarchical States Superstates with history property Exercise independent behavior at the same time Broadcast events to orthogonal states

The Hierarchical Statechart Pattern n Context: You are using the Basic Statechart. The application is large and the states seem to have a hierarchical nature. n Problem: How do you implement the states hierarchy (Macro states) in your design?

The Hierarchical Statechart pattern n Solution: To implement hierarchy in your design, you have to distinguish different types of states: – A SimpleState : a state that is not part of any superstate and doesn't contain any child state. (no parent and no children) – A Leaf State: a state that is child of a superstate but doesn't have any children (has a parent but has no children). – A Root SuperState: a state that encapsulates a group of other states (children) but has no parent. – An Intermediate SuperState: a state that encapsulates a group of other states (children) and has a parent state.

The Hierarchical Statechart pattern structure Actions Events Simple State Entity_State Entity_Interface Entity_State : AState* Event_Dispatcher (Event) UpdateState(New_State : AState*) Entity_Ref * CurrentState RootSuperState CurrentState : AState* set_super_state (NewState : AState*) IntermediateSuperState MySuperState : AState* CurrentState : AState* set_super_state (NewState : AState*) LeafState MySuperState : AState* AState $ Entity_Ref : Entity_Interface * Num_States : int NextStates : AState** set_entity_state (New_State : AState*) set_super_state (New_State : AState*) entry () exit () * MySuperState CurrentState NextStates

The Hierarchical Statechart pattern structure n RootSuperState – Keeps track of which of its children is the current state using CurrentState – Handles event addressed to the group and dispatches them to the current state to respond accordingly. – Produces common outputs for children states, and it can also implement the common event handling methods on their behalf. – Performs state-driven transitions from self to the next upcoming states. – Implements the entry and exit methods for the whole superstate. n IntermediateSuperState – Does the functionality of both the RootSuperState and the LeafState. n LeafState – Does the same functionality as a SimpleState and additionally uses a MySuperState pointer to change the current active state of its parent class.

A hierarchical statechart for the coin machine example Broken Fixed Failed Locked Unlocked Coin Pass Coin S_Functioning Coin

The coin machine design using the Hierarchical Statechart pattern Broken Fixed Failed Locked Unlocked Coin Pas s Coin S_Functioning Coin

A pattern Language for StateCharts StateChart Patterns Roadmap State State Transition Mechanism Finite State Machines Basic Statechart Hierarchical Statechart Orthogonal Behavior Broadcasting History State Basic Statechart Specification Using Hierarchical States Superstates with history property Exercise independent behavior at the same time Broadcast events to orthogonal states

The Orthogonal Behavior pattern n Context: You are using Hierarchical Statechart. Your entity has several independent behaviors that it exercises at the same time. n Problem: How can you deploy the entity's orthogonal behaviors in your design? n Solution: – identify those super states that run orthogonal (concurrently) and dispatch the events to each of those states. – Define a Virtual superstate as a collection of superstates that process same events. Then group these states in a virtual superstate whose event method will call all the event method of the attached superstates. A B C B i C gh E F g D V Example of a virtual superstate

The structure of the Orthogonal Behavior Pattern Actions Events Simple State Entity_State Entity_Interface Entity_State : AState* Event_Dispatcher (Event) UpdateState(New_State : AState*) Entity_Ref * CurrentState RootSuperStat e CurrentState : AState* set_super_state (NewState : AState*) 1 IntermediateSuperState MySuperState : AState* CurrentState : AState* set_super_state (NewState : AState*) LeafState MySuperState : AState* 1 VirtualState IndependentStates : AState** Add (State : AState*) * AState $ Entity_Ref : Entity_Interface * Num_States : int NextStates : AState** $ Conditions set_entity_state (New_State : AState*) set_super_state (New_State : AState*) entry () exit () Add (state : AState*) * 1 1 NextStates *

An orthogonal statechart of the coin machine WarningOFF WarningON Failed Fixed Broken Fixed Failed Locked Unlocked Coin Pass Coin S_Functioning S_Operation S_Warning V_CoinMachine Coin Independent behavior describing the warning and operation concurrent behavior

The coin machine design using the Orthogonal Behavior pattern Actions Events Simple State Machine_State CoinMachine_Interface Machine_State : AState* Event_Dispatcher (Event) UpdateState(New_State : AState*) Machine_Ref * CurrentState RootSuperState CurrentState : AState* set_super_state (NewState:AState*) 1 IntermediateSuperState MySuperState : AState* CurrentState : AState* set_super_state (NewState : AState*) LeafState MySuperState : AState* 1 VirtualState IndependentStates : AState** Add (State : AState*) * AState $ Machine_Ref : CoinMachine_Interface * Num_States : int NextStates : AState** $ Conditions set_entity_state (New_State : AState*) set_super_state (New_State : AState*) entry () exit () Add (state : AState*) * 1 1 * V_CoinMachine Failed () Fixed () S_Operation Fixed () Failed () S_Warning Fixed () Failed () NextStates // Failed // for all independent states s in V_CoinMachine s->Failed()

Another Example From CODE GENERATION FROM UML STATECHARTS, Niaz et al, SEA 2003 CODE GENERATION FROM UML STATECHARTS, Niaz et al, SEA 2003

Design proposed in Niaz et al, SEA 2003Niaz et al, SEA 2003

StateChart-based Design in Niaz et al, SEA 2003Niaz et al, SEA 2003 n The AirCon class is the super context class n Each action becomes a method of the context class. n The state object will hold the reference of the current active state. n The history node is implemented by providing a reference opHistory in the AirCon object n The AirConState and AbsOpState classes are the abstract state classes, which provide a common interface for theconcrete state classes. n The AirCon (context) object delegates all incoming events to its current state object (state) n Operating class becomes context for the nested statechart.

Statechart having Orthogonal or concurrent states

Class diagram for implementing concurrent substates from Niaz et al

Implementing concurrent substates from Niaz et al n Implement the concurrent substates by extending the state pattern with object composition and delegation. n The Operating state becomes the context for both concurrent regions Mode and Speed. n Mode and Speed will become the abstract classes and will define the interface for the behavior associated with nested sequential substates

Auto-coding UML Statecharts for Flight Software Benowitz et al, JPL and CalTech, 2nd IEEE International Conference on Space Mission Challenges for Information Technology (SMC-IT'06) Notice the use of the composite pattern used to describe composite states as in the Yacoub et al pattern