UML Review: State Machines
Sept. 17, 2003Lecture 5: CS660 Fall Overview States Transitions Activities Modeling object lifeline Creating well-structured algorithms
Sept. 17, 2003Lecture 5: CS660 Fall Thermostat Example
Sept. 17, 2003Lecture 5: CS660 Fall Terms & Concepts State machine--behavior that specifies –the sequences of states an object goes through during its lifetime, and –the events and transitions between those states, and –responses to the events. State--condition or situation during the life of an object during which it satisfies some condition, performs some activity, or waits for some event.
Sept. 17, 2003Lecture 5: CS660 Fall Terms & Concepts (cont.) Event--specification of a significant occurrence that has a location in time and space. Transition--relationship between two states indicating that an object in the first state will perform certain actions and enter the second state upon occurrence of a specified event.
Sept. 17, 2003Lecture 5: CS660 Fall Terms & Concepts (cont.) Activity--ongoing non-atomic execution within a state machine. Action--executable atomic computation that results in a change in state of the model or the return of a value.
Sept. 17, 2003Lecture 5: CS660 Fall States State parts: –Name--distinguishing textual string; note: some states may be anonymous –Entry/exit actions--action executed on traversing a transition. –Internal transitions--no change in state. –Substates--nested structure of states –Deferred events--events not handled by a state, but are queued for later processing.
Sept. 17, 2003Lecture 5: CS660 Fall State Depicted in UML Rectangle with rounded corners. Initial state is filled black circle. Final state is an unfilled circle containing a filled black circle.
Sept. 17, 2003Lecture 5: CS660 Fall Transitions Transition parts: –Source state--the active state preceding the transition; it is affected by the transition. –Event trigger--event received by the source that causes the transition to “fire”. –Guard--boolean expression which must be true before the transition can fire. –Action--atomic computation that occurs during the transition. –Target state--the active state following the transition.
Sept. 17, 2003Lecture 5: CS660 Fall Transitions Depicted in UML
Sept. 17, 2003Lecture 5: CS660 Fall Advanced States Entry & exit actions--actions that always occur upon entry into or exit away from a state regardless of transition. Internal Transitions--triggered by events but don’t change state. Activities--ongoing behavior which continues until interrupted. Deferred events--events ignored by the current state, but postponed for later processing.
Sept. 17, 2003Lecture 5: CS660 Fall Advanced States (cont.)
Sept. 17, 2003Lecture 5: CS660 Fall Substates Substate--state nested inside of another state. Sequential substates History states Concurrent substates
Sept. 17, 2003Lecture 5: CS660 Fall Modelling Object Lifetime Set the context for the state machine: class, use case, or whole system. –Collect neighboring classes with any relationship; these are potential targets for actions and candidates for guards. –For an entire system, focus on one behavior of the system. Identify the initial and final states; define pre- and post-conditions
Sept. 17, 2003Lecture 5: CS660 Fall Modeling Object Lifetime (cont.) Decide on events to which the element will respond. Layout the top-level states and connect with appropriate transitions. Identify entry/exit actions. Expand states as necessary (identify substates)
Sept. 17, 2003Lecture 5: CS660 Fall UML is not Enough UML can represent many features But UML still cannot represent something –To model a network, how to represent routers & hubs. –How to keep track of the version number of a subsystem. –How to represent some constraints in a system.
Sept. 17, 2003Lecture 5: CS660 Fall UML Extension Mechanism Adornments –Notes Extensibility mechanisms –Stereotypes –Tagged values –Constraints Modeling Techniques Extending UML
Sept. 17, 2003Lecture 5: CS660 Fall Notes Notes—graphical symbol for rendering constraints or comments attached to an element or collection of elements. Representing the meaning of the model. Specify things like –Requirements –Observations –Reviews –Explanations –Constraints Rendered as a rectangle with a dog-eared corner.
Sept. 17, 2003Lecture 5: CS660 Fall Notes (cont.) May contain combination of text and graphics. May contain URLs linking to external documents. See for related information. See encrypt.doc for details about this algorithm.
Sept. 17, 2003Lecture 5: CS660 Fall Stereotypes Stereotype—extension of the UML vocabulary. Metatype Allows for new building blocks. Graphically rendered as –Name enclosed in guillemets > «stereotype» –New icon «metaclass» ModelElement Internet
Sept. 17, 2003Lecture 5: CS660 Fall Tagged Values Tagged value—extension of the properties of a UML element. Metadata—data applies to the element; not to instances of the element. Rendered as a text string enclosed in braces { } Placed below the name of another element. Properties; name/value pairs {name=value} > Billing {version=3.2}
Sept. 17, 2003Lecture 5: CS660 Fall Constraints Constraint—extension of the semantics of a UML element. Allows new or modified rules. –Conditions that must hold true. Rendered in braces {}. –Free-form text. –UML’s Object Constraint Language (OCL). –Can be contained in note.
Sept. 17, 2003Lecture 5: CS660 Fall Modeling Comments Place as text in note next to related element. Connect notes using dependencies if necessary. Hide or show as appropriate; Place lengthy comments in external files linked to the diagram through a note. Keep comments that record decisions. Keep historic comments.
Sept. 17, 2003Lecture 5: CS660 Fall Modeling New Building Blocks First attempt to use basic UML. Identify a basic UML component that closely approaches the new concept and define a stereotype. Specify properties and semantics using tagged values and constraints. For a distinctive visual cue, define a new icon.