Presentation is loading. Please wait.

Presentation is loading. Please wait.

 2000 Deitel & Associates, Inc. All rights reserved. Optional Case Study - Chapter 3 Outline 3.1 Introduction 3.2 Class Attributes 3.3 Statechart Diagrams.

Similar presentations


Presentation on theme: " 2000 Deitel & Associates, Inc. All rights reserved. Optional Case Study - Chapter 3 Outline 3.1 Introduction 3.2 Class Attributes 3.3 Statechart Diagrams."— Presentation transcript:

1  2000 Deitel & Associates, Inc. All rights reserved. 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

2  2000 Deitel & Associates, Inc. All rights reserved. 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  2000 Deitel & Associates, Inc. All rights reserved. 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

4  2000 Deitel & Associates, Inc. All rights reserved. 3.2 Class Attributes (II)

5  2000 Deitel & Associates, Inc. All rights reserved. 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

6  2000 Deitel & Associates, Inc. All rights reserved. 3.2 Class Attributes (III) - Class Diagram with Attributes Elevator currentFloor : int = 1 direction : enum = up capacity : int = 1 arrivalTime : int moving : bool = false Scheduler floor1ArrivalTime : int floor2ArrivalTime : int Floor capacity : int = 1 occupied : bool = false FloorButton pressed : bool = false Door open : bool = false Bell Light on : bool = false ElevatorButton pressed : bool = false Building Person ID : int Clock time : int = 0 Person ID : int

7  2000 Deitel & Associates, Inc. All rights reserved. 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 Not pressed button reset button press Pressed

8  2000 Deitel & Associates, Inc. All rights reserved. 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 Waiting Moving button press [ other floor ] / arrivalTime = currentTime + 5 button press [ need to move ] when [ currentTime == arrivalTime ] button press [ current floor ] [ no further requests ] Servicing Floor exit/ close door

9  2000 Deitel & Associates, Inc. All rights reserved. 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

10  2000 Deitel & Associates, Inc. All rights reserved. 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)

11  2000 Deitel & Associates, Inc. All rights reserved. 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 [ ]

12  2000 Deitel & Associates, Inc. All rights reserved. 3.5 Activity Diagram (III) [ in motion] Move to other floor [ button pressed] Stop moving Reset elevator button Ring bell Open door [ current floor button pressed] [ current floor button not pressed] [ currentTime < arrivalTime] [ currentTime == arrivalTime] Close door Guard conditions

13  2000 Deitel & Associates, Inc. All rights reserved. 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

14  2000 Deitel & Associates, Inc. All rights reserved. 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


Download ppt " 2000 Deitel & Associates, Inc. All rights reserved. Optional Case Study - Chapter 3 Outline 3.1 Introduction 3.2 Class Attributes 3.3 Statechart Diagrams."

Similar presentations


Ads by Google