140 likes | 185 Views
Optional Case Study - Chapter 3. Outline 3.1 Introduction 3.2 Class Attributes 3.3 Statechart Diagrams 3.4 Elevator Statechart Diagram 3.5 Activity Diagrams 3.6 Conclusion. 3.1 Introduction. Previous chapter First phase - identify classes
E N D
Optional Case Study - Chapter 3 Outline 3.1 Introduction 3.2 Class Attributes 3.3 Statechart Diagrams 3.4 Elevator Statechart Diagram 3.5 Activity Diagrams 3.6 Conclusion
3.1 Introduction • Previous chapter • First phase - identify classes • List nouns, created separate class for each category • Represented classes and relationships in UML class diagram • Classes have • Attributes - data • Focus of this chapter • Example: A radio's attributes include volume setting, AM/FM • Operations - functions • Focus of Chapter 4
3.2 Class Attributes • Class Attributes • Describe classes • Identify attributes by looking for descriptive words in problem statement • Create an attribute for each descriptive word/phrase • Create attributes to represent data a class may need
3.2 Class Attributes (III) • Notice • Bell and Building have no attributes • As we continue the case study, we will add, modify, and delete information about the classes • Attributes • Name • Type • Initial value • If no initial value, only name and type shown • Random numbers • Example: capacity : int = 1 • For now, not overly concerned with types or initial values • Include information we can get from problem statement
3.2 Class Attributes (III) - Class Diagram with Attributes Elevator Clock Door currentFloor : int = 1 time : int = 0 open : bool = false direction : enum = up capacity : int = 1 arrivalTime : int Floor moving : bool = false Bell capacity : int = 1 <none yet> occupied : bool = false Scheduler Light floor1ArrivalTime : int FloorButton floor2ArrivalTime : int on : bool = false pressed : bool = false Person Person ElevatorButton Building ID : int ID : int pressed : bool = false <none yet>
button press Pressed Not pressed button reset 3.3 Statechart Diagrams • States • Describe condition of an object at a given point in time • Statechart diagrams (state diagrams) • Express how, and under what conditions, objects change state • Format • Rounded rectangle - represents a state • Solid circle with arrowhead - points to initial state • Solid lines with arrows - transitions • Object can transition in response to an event • Name of event written near line
button press [need to move] button press [other floor]/ arrivalTime = currentTime + 5 Servicing Floor when [currentTime == arrivalTime] button press [current floor] Waiting [no further requests] Moving exit/ close door 3.4 Elevator Statechart Diagram • Guard condition - transition only occurs if condition met • Elevator transitions from "Waiting" state to "Servicing Floor" state when a button is pressed on the elevator's floor • Forward slash / - indicates action with state change
3.4 Elevator Statechart Diagram (II) • true condition • State transition if a certain condition is true when [currentTime == arrivalTime] • Elevator transitions from "Moving" state to "Servicing Floor" state • Actions • Model actions by splitting state into Top: state name Bottom: state actions • Exit - action label, indicates an action to be performed when an object exits a state • Elevator must "close door" when exits "Servicing Floor" state • If elevator needs to move, it must first close the door
3.5 Activity Diagrams • Activity diagram • Variation of statechart diagram • Statechart diagram does not how the elevator decides if it needs to move • Models what object does during its lifetime (its activities)
3.5 Activity Diagrams (II) • Format • Activities modeled as ovals (name inside oval) • Solid line with arrowhead - connects two activities • Indicates order activities are performed • Solid circle - starting point of sequence of activities • In our example, each time button pressed, sequence of activities are executed • Double circle (bull's eye) - ending point of diagram • Diamond - decision • Each line extending from diamond is a different set of activities • Guard condition indicates which path to choose in square brackets [ ]
button pressed] [ in motion] [ currentTime == current floor button [ [ arrivalTime] not pressed] current floor [ Close door button pressed] Move to other floor Stop moving currentTime < [ arrivalTime] Reset elevator button Ring bell Guard conditions Open door 3.5 Activity Diagram (III)
3.5 Activity Diagrams (IV) • When button pressed • Elevator in "Moving" state • Path terminates (elevator cannot immediately perform any activities) • If button pressed on elevator's current floor • Reset button • Ring bell • Open door • If button not on elevator's floor • Close door • Move to other floor • Stop at other floor
3.6 Conclusion • We have • Expanded knowledge of classes • Represented new knowledge in class diagram • Used statecharts • Gained information on how our system works • Chapters 4 and 5 • Determine operations associated with classes • Determine how classes interact (collaborate) • Randomness arrivalTime = currentTime + ( 5 + rand() % 16 ); • Can be used to schedule next arrival of person on floor