29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

18.2.3.1 A start point<br />

A start point is the point at which the state diagram is initialized. In the figure, there are actually four<br />

start points indicated (‘Start’, ‘lock’, ‘close’ <strong><strong>an</strong>d</strong> ‘unlock’). The ‘Start’ start point is the initial entry<br />

point for the whole diagram, while the other three indicated start points are for sub State diagrams.<br />

Any preconditions required by the State diagram c <strong>an</strong> be specified on the tr<strong>an</strong>sition from the start<br />

point (for example, in the figure the tr<strong>an</strong>smittedID must be the same as the memoryID memorized by<br />

the system). It is the initial tr<strong>an</strong>sition from which all other tr<strong>an</strong>sitions em<strong>an</strong>ate. This tr<strong>an</strong>sition is<br />

automatically taken when the State diagram is executed. Note that the initial ‘Start’ point is not<br />

equivalent to a state.<br />

18.2.3.2 Events<br />

Events are one way asynchronous tr<strong>an</strong>smissions of information from one object to <strong>an</strong>other. They c<strong>an</strong><br />

possess parameters with names <strong><strong>an</strong>d</strong> types. The general format of <strong>an</strong> event is: eventName<br />

(parameter:type, ...). Of course m<strong>an</strong>y events do not have <strong>an</strong>y associated parameters.<br />

18.2.3.3 A set of tr<strong>an</strong>sitions<br />

These are the statements which move the system from one state to <strong>an</strong>other. In the state diagrams eac<br />

tr<strong>an</strong>sition is formed of four (optional) parts:<br />

h<br />

1. <strong>an</strong> event (e.g. lock).<br />

2. a condition (e.g. tr<strong>an</strong>smittedID = memoryID]<br />

3. the initiated event (e.g. ^EngineM<strong>an</strong>agementUnit.locked)<br />

4. <strong>an</strong> operation (e.g. /setDoorToLock)<br />

The event is what triggers the tr<strong>an</strong>sition, howev er the tr<strong>an</strong>sition will only occur if the condition is<br />

met. If the event occurs <strong><strong>an</strong>d</strong> the conditions are met, then the associated operation is performed. An<br />

operation is a segment of code (equivalent to a statement or program or method within a programming<br />

l<strong>an</strong>guage) which causes the system state to be altered. Some tr<strong>an</strong>sitions c<strong>an</strong> also trigger <strong>an</strong> event which<br />

should be sent to a specified object. For example, the above example sends <strong>an</strong> event locked to the<br />

EngineM<strong>an</strong>agementUnit. The process of sending a global event is a special case of sending <strong>an</strong> event to a<br />

specified object.<br />

The syntax of <strong>an</strong> event is therefore:<br />

event(arguments) [condition] ^target.sendEvent(arguments) /operation(arguments)<br />

18.2.3.4 A set of state variables<br />

These are variables referred to in a State diagr<br />

have the format name: type = value.<br />

am (for example memoryID is a state variable). They<br />

18.2.3.5 A set of states<br />

A state represents a period of time during which <strong>an</strong> object is waiting for <strong>an</strong> event to occur. It is <strong>an</strong><br />

abstraction of the attribute values <strong><strong>an</strong>d</strong> links of a n object. A state is drawn as a rounded box containing<br />

the (optional) name of the state. A state may often be composed of other states (the combination of<br />

which represents the higher level state). A state has duration, that is it occupies <strong>an</strong> interval of time.<br />

A state box c<strong>an</strong> contain two additional sections, one section containing a list of state variables <strong><strong>an</strong>d</strong><br />

the other section containing a list of triggered operations (as illustrated by Figure 18.5).<br />

car alarmed<br />

sensors: List = {}<br />

entry / set alarm active<br />

do / check sensors<br />

exit / set alarm inactive<br />

Figure 18.5: State box with state variables <strong><strong>an</strong>d</strong> triggered operations<br />

151

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!