cxstates

14

Click here to load reader

Upload: esug

Post on 23-Jun-2015

182 views

Category:

Technology


0 download

DESCRIPTION

CxStates. ESUG 2006, Prague

TRANSCRIPT

Page 1: CxStates

abcdefg

CxStates

Little Smalltalk Exercise:A dynamically defined state model

not based on the state pattern

presented byAlfred WullschlegerSwiss National Bank

Page 2: CxStates

abcdefg

awu060829 2

The Author● Smalltalker since 1992● Project OVID at Fides Informatik (1992-1999)

– OVID currently in production more than 11 years● Project OASE at Swiss National Bank (since

1999 in production)– Financial Statistics from Swiss Banks and

Companies– based on Gemstone/S and VisualWorks– ongoing development under full production

Page 3: CxStates

abcdefg

awu060829 3

Motivation● We needed a user configurable state model

– so, preferably should not be class based– should allow easy communication with the „outer

system“ = the system components which are not part of the state model itself

● Solution: CxStates– ANSI Event Model as implementation pattern

Page 4: CxStates

abcdefg

awu060829 4

Basic classes (1)● CxBaseState

– defines a state● has a name● has a transitionTable

– contains legal transitions to other states through transition entries

● CxTransitionEntry– defines a transition by a symbol and the new state

● includes transitionActions

Page 5: CxStates

abcdefg

awu060829 5

Basic Classes (2)● CxActionSequence and CxAction

– for execution of methods in the „outer System“– extensible analoguous to the event model

● CxStateEnsemble– Defines a complete state diagram– Defines all legal transition symbols

Page 6: CxStates

abcdefg

awu060829 6

Action execution

currentState

newState

Transition

PreTransitionActions

PostTransitionActions

preTransitionActions in context of current statepostTransitionActions in context of new state

Page 7: CxStates

abcdefg

awu060829 7

Action

CxAction

A CxAction contains a message send. CxAction is declared in the

transitionEntry. The message receiver is typically inserted during

the transition

Page 8: CxStates

abcdefg

awu060829 8

Declaration of actions● in CxBaseState:

– whenCxPreTransition: aTransitionSymbol send: aSelector to: aReceiver

● adds a CxAction to the PreTransitionActionSequence● aReceiver can be nil: the receiver can be dynamically set

when the transition is executed● polymorphically delegated to CxTransitionEntry

– whenCxPostTransition: aTransitionSymbol send: aSelector to: aReceiver

● the same in context of the new state

Page 9: CxStates

abcdefg

awu060829 9

CxTransitionContext● Is an argument holder for the messages sent to

the „outer system“ – combines receiver and arguments for the declared

action– includes currentState (either the pre- or the

postTransition state!)● CxBaseState>>doTransition:

aCxTransitionContext– Basic method for the execution of the transition

Page 10: CxStates

abcdefg

awu060829 10

CxBaseState>>doTransition:● Executes the defined CxActions

– By delegation to CxTransitionEntry>>doTransition: , and finally to CxAction>>doTransition:

● Returns– nil, when the transition is illegal, state unchanged– false, when the transition is inhibited, state

unchanged– the new state, in all other cases

● Inhibit by a special CxAction: CxCondition– Must returns true or false

Page 11: CxStates

abcdefg

awu060829 11

Demonstration● Automatic Coffee Machine

– Power switch– „Make Coffee“ button– grinding automatic (timer)– Heating (temperature sensor, not simulated)– brewing automatic (timer)– „Stopp brewing“ button– Water supply not simulated

Page 12: CxStates

abcdefg

awu060829 12

Coffee States

Switched Off

Switched On

Grinding/Heating

Heating

Brewing

Init

initializeMachine

switchPowerOn

pressButtonForCoffeestopGrinding

startBrewingcupFilled

cancelBrewing

Page 13: CxStates

abcdefg

awu060829 13

Extensions● CxCondition

– allows to inhibit preTransitions by outer system conditions

– analogous to CxActions but must return a boolean● CxPostTransitionEntry

– technical class for post states which do not contain transitionEntries for the corresponding transition symbol

– PostTransitionEntries must be defined in the post state!

Page 14: CxStates

abcdefg

awu060829 14

Thank you for listening

Questions?