object oriented analysis and design
DESCRIPTION
Object Oriented Analysis and Design. Object-Oriented Analysis Statement of what our client wants Object-Oriented Design How to provide it using OO tools. Tasks. Provide a problem statement (requirements analysis) Multiple discussions with client - PowerPoint PPT PresentationTRANSCRIPT
11
Object Oriented Analysis and Object Oriented Analysis and DesignDesign
22
Object-Oriented AnalysisObject-Oriented Analysis Statement of what our client wantsStatement of what our client wants
Object-Oriented DesignObject-Oriented Design How to provide it using OO toolsHow to provide it using OO tools
33
TasksTasks
Provide a problem statement (requirements analysis)Provide a problem statement (requirements analysis)– Multiple discussions with clientMultiple discussions with client
Determine objects needed to implement the systemDetermine objects needed to implement the system– Look for nouns in problem statementLook for nouns in problem statement
Determine object attributesDetermine object attributes– What do I know?What do I know?– How are the nouns described?How are the nouns described?
Determine object behaviorsDetermine object behaviors– What can I do?What can I do?– Look for verbs in problem statementLook for verbs in problem statement
44
Key RuleKey Rule
Information HidingInformation Hiding Though objects know how to communicate Though objects know how to communicate
with one another across well-defined with one another across well-defined interfaces, objects are normally not allowed interfaces, objects are normally not allowed to know how other objects are implementedto know how other objects are implemented
55
Unified Modeling LanguageUnified Modeling Language
OOD ToolOOD Tool We use C++ to communicate our instructions to a We use C++ to communicate our instructions to a
computercomputer Designers use UML to communicate their Designers use UML to communicate their
instructions to those who will do the codinginstructions to those who will do the coding Important namesImportant names
– Grady BoochGrady Booch– James RumbaughJames Rumbaugh– Ivar JacobsenIvar Jacobsen
All worked at Rational Software in the late 90’sAll worked at Rational Software in the late 90’s
66
Simulation of a Two Floor ElevatorSimulation of a Two Floor Elevator
77
Problem StatementProblem Statement
A A company wants to build a two-floor office building and equip it with an elevator. The company wants to build a two-floor office building and equip it with an elevator. The company wants you to develop an object-oriented software simulator in C++ . Net that company wants you to develop an object-oriented software simulator in C++ . Net that models the operation of the elevator to determine whether the elevator suits the models the operation of the elevator to determine whether the elevator suits the company’s needs. company’s needs.
Your simulator should include a clock that begins with its time, in seconds, set to zero Your simulator should include a clock that begins with its time, in seconds, set to zero The clock ticks every second, but it does not keep track of hours and minutes. Your The clock ticks every second, but it does not keep track of hours and minutes. Your simulator also should include a scheduler that begins the day by scheduling two times simulator also should include a scheduler that begins the day by scheduling two times randomly: the time when a person first steps onto floor 1 and presses the button on that randomly: the time when a person first steps onto floor 1 and presses the button on that floor to summon the elevator, and the time when a person first steps onto floor 2 and floor to summon the elevator, and the time when a person first steps onto floor 2 and presses the button on that floor to summon the elevator. presses the button on that floor to summon the elevator.
Each of these times is a random integer in the range from 5 to 20 seconds, inclusive. Each of these times is a random integer in the range from 5 to 20 seconds, inclusive. When the clock time equals the earlier of these two times, the scheduler creates a When the clock time equals the earlier of these two times, the scheduler creates a person, who then walks onto the appropriate floor and presses the floor button. The floor person, who then walks onto the appropriate floor and presses the floor button. The floor button illuminates, indicating that it has been pressed. button illuminates, indicating that it has been pressed. [Note: [Note: The illumination of the floor The illumination of the floor button occurs automatically when the button is pressed and needs no programming; the button occurs automatically when the button is pressed and needs no programming; the light built into the button turns off automatically when the button is reset.] At the light built into the button turns off automatically when the button is reset.] At the beginning of the simulation, the elevator starts the day waiting with its door closed on beginning of the simulation, the elevator starts the day waiting with its door closed on floor 1. To conserve energy, the elevator moves only when necessary. The elevator floor 1. To conserve energy, the elevator moves only when necessary. The elevator alternates directions between moving up and moving down.alternates directions between moving up and moving down.
88
For simplicity, the elevator and each of the floors have a capacity of one For simplicity, the elevator and each of the floors have a capacity of one person. The scheduler first verifies that a floor is unoccupied before creating person. The scheduler first verifies that a floor is unoccupied before creating a person to walk onto that floor. If the floor is occupied, the scheduler delays a person to walk onto that floor. If the floor is occupied, the scheduler delays creating the person by one second (thus allowing the elevator an creating the person by one second (thus allowing the elevator an opportunity to pick up the person and move to the floor). After a person opportunity to pick up the person and move to the floor). After a person walks onto a floor, the scheduler creates the next random time (between 5 walks onto a floor, the scheduler creates the next random time (between 5 and 20 seconds into the future) for a person to walk onto that floor and press and 20 seconds into the future) for a person to walk onto that floor and press the floor button. the floor button.
When the elevator arrives at a floor, it resets the elevator button and sounds When the elevator arrives at a floor, it resets the elevator button and sounds the elevator bell (which is inside the elevator). The elevator then signals its the elevator bell (which is inside the elevator). The elevator then signals its arrival to the floor. The floor, in response, resets the floor button and turns arrival to the floor. The floor, in response, resets the floor button and turns on the floor's elevator-arrival light. The elevator then opens its door. on the floor's elevator-arrival light. The elevator then opens its door. [Note: [Note: The door on the floor opens automatically with the elevator door and needs The door on the floor opens automatically with the elevator door and needs no programming.] The elevator's passenger, if there is one, exits the no programming.] The elevator's passenger, if there is one, exits the elevator, and a person, if there is one waiting on that floor, enters the elevator, and a person, if there is one waiting on that floor, enters the elevator. Although each floor has a capacity of one person, assume there is elevator. Although each floor has a capacity of one person, assume there is enough room on each floor for a person to wait on that floor while the enough room on each floor for a person to wait on that floor while the elevator's passenger exits. elevator's passenger exits.
99
A person entering the elevator presses the elevator button, which illuminates A person entering the elevator presses the elevator button, which illuminates (automatically, without programming) when pressed and turns off when the (automatically, without programming) when pressed and turns off when the elevator arrives on the floor and resets the elevator button. elevator arrives on the floor and resets the elevator button. [Note: [Note: Because the Because the building has only two floors, only one elevator button is necessary; this button building has only two floors, only one elevator button is necessary; this button notifies the elevator to move to the other floor.] Next, the elevator closes its door notifies the elevator to move to the other floor.] Next, the elevator closes its door and begins moving to the other floor. When the elevator arrives at a floor, if a and begins moving to the other floor. When the elevator arrives at a floor, if a person does not enter the elevator and the floor button on the other floor has not person does not enter the elevator and the floor button on the other floor has not been pressed, the elevator closes its door and remains on that floor until another been pressed, the elevator closes its door and remains on that floor until another person presses a button on a floor.person presses a button on a floor.
For simplicity, assume that all the activities that happen, from when the elevator For simplicity, assume that all the activities that happen, from when the elevator reaches a floor until the elevator closes its door, take zero time. reaches a floor until the elevator closes its door, take zero time. [Note: [Note: Although Although these activities take zero time, they still occur sequentially; e.g., the elevator door these activities take zero time, they still occur sequentially; e.g., the elevator door must open before the passenger exits the elevator.] The elevator takes five must open before the passenger exits the elevator.] The elevator takes five seconds to move from one floor to the other. Once per second, the simulator seconds to move from one floor to the other. Once per second, the simulator provides the time to the scheduler and to the elevator. The scheduler and elevator provides the time to the scheduler and to the elevator. The scheduler and elevator use the time to determine what actions each must take at that particular time. use the time to determine what actions each must take at that particular time. The simulator should display messages on the screen that describe what is The simulator should display messages on the screen that describe what is happening.happening.
1010
Issues in Building a SimulatorIssues in Building a Simulator
World PortionWorld Portion– Items to modelItems to model– PersonPerson– ElevatorElevator– Buttons and LightsButtons and Lights
Controller PortionController Portion– Elements needed to simulate world portionElements needed to simulate world portion– SchedulerScheduler– People CreatorPeople Creator
1111
Use Case DiagramsUse Case Diagrams
Helps the analyst complete the Helps the analyst complete the requirements analysisrequirements analysis
Models the interactions between the Models the interactions between the system’s external clients and the “use system’s external clients and the “use cases” of the system.cases” of the system.
Each use case represents a different Each use case represents a different capability that the system provides to its capability that the system provides to its clientsclients
1212
The goal of the use-case diagram is to show The goal of the use-case diagram is to show the kinds of interaction users have with the the kinds of interaction users have with the system without providing all of the details.system without providing all of the details.
Change Floors
1313
Identifying ClassesIdentifying Classes Look for the nouns in the problem statementLook for the nouns in the problem statement
– CompanyCompany– BuildingBuilding– ElevatorElevator– SimulatorSimulator– ClockClock– TimeTime– SchedulerScheduler– PersonPerson– Floor 1Floor 1– Floor buttonFloor button– Floor 2Floor 2– Elevator doorElevator door– EnergyEnergy– CapacityCapacity– Elevator buttonElevator button– Elevator bellElevator bell– Floor’s elevator arrival lightFloor’s elevator arrival light– Person waiting on a floorPerson waiting on a floor– Elevator’s passengerElevator’s passenger
1414
Diagram to Associate ClassesDiagram to Associate Classes
Diamond indicates compositionDiamond indicates composition ““One object of class Elevator services two One object of class Elevator services two
objects of class Floor”objects of class Floor”
1515
Full Class Diagram for Elevator Full Class Diagram for Elevator SimulatorSimulator
1616
Identifying Class AttributesIdentifying Class Attributes
What Do I knowWhat Do I know– A class’s attributes are implemented in a C++ A class’s attributes are implemented in a C++
program as dataprogram as data– Locate descriptive words and phrasesLocate descriptive words and phrases
1717
AttributesAttributesClassClass1.1. ElevatorElevator
2.2. ClockClock
3.3. SchedulerScheduler
4.4. PersonPerson
5.5. FloorFloor
6.6. Floor ButtonFloor Button
7.7. Elevator ButtonElevator Button
8.8. DoorDoor
9.9. BellBell
10.10. LightLight
11.11. BuildingBuilding
Descriptive Word/PhraseDescriptive Word/Phrase1.1. Waits on floor 1Waits on floor 1
Alternates directionAlternates directionCapacity of 1Capacity of 15 seconds to move between floors5 seconds to move between floorsElevator movingElevator moving
2.2. Begins at 0Begins at 0
3.3. Creates the next random time for a person to walk onto a floor Creates the next random time for a person to walk onto a floor
4.4. Person numberPerson number
5.5. Capacity of 1Capacity of 1Occupied/unoccupiedOccupied/unoccupied
6.6. Pressed/resetPressed/reset
7.7. Pressed/resetPressed/reset
8.8. Shut/openShut/open
9.9. None in problem statementNone in problem statement
off/onoff/on
None in problem statementNone in problem statement
1818
Class Diagram with AttributesClass Diagram with Attributes
1919
State Chart DiagramsState Chart Diagrams
Objects in a system have statesObjects in a system have states The values of the attributes define the stateThe values of the attributes define the state State chart diagrams let us express how State chart diagrams let us express how
objects change stateobjects change state
2020
Button has two StatesButton has two StatesElevator has three statesElevator has three statesEvents that trigger state change are noted next to the dotted linesEvents that trigger state change are noted next to the dotted linesText in brackets called “guard conditions”. Stipulates the conditions Text in brackets called “guard conditions”. Stipulates the conditions under which the state change occursunder which the state change occurs/ is an action label. It says that the door is closed after the state is / is an action label. It says that the door is closed after the state is exitedexitedSplit of servicing Floor state into two compartments means that an Split of servicing Floor state into two compartments means that an action can be performed while in a state (in this case, closing a door)action can be performed while in a state (in this case, closing a door)
2121
Activity DiagramsActivity Diagrams
Focuses on the action that an object Focuses on the action that an object performs – as opposed to the state changeperforms – as opposed to the state change
2222
Diamonds indicate decisionsDiamonds indicate decisionsText indicates branches of Text indicates branches of decisionsdecisions
2323
What Can I do?What Can I do?Look for Verb PhrasesLook for Verb Phrases
ClassClass ElevatorElevator
ClockClock SchedulerScheduler
PersonPerson
FloorFloor Floor ButtonFloor Button Elevator ButtonElevator Button DoorDoor LightLight BuildingBuilding
Verb PhraseVerb Phrase Moves, arrives at a floor, resets the elevator button, Moves, arrives at a floor, resets the elevator button,
sounds the elevator bell, signals its arrival, opens its sounds the elevator bell, signals its arrival, opens its door, closes its doordoor, closes its door
Ticks every secondTicks every second Randomly Schedules times, creates a person, verifies Randomly Schedules times, creates a person, verifies
that the floor is unoccupied, delays creating a person that the floor is unoccupied, delays creating a person by one secondby one second
Steps onto a floor, presses floor button, presses Steps onto a floor, presses floor button, presses elevator button, enters elevator, exits elevatorelevator button, enters elevator, exits elevator
Resets floor button, turns off light, turns on lightResets floor button, turns off light, turns on light Summons elevatorSummons elevator Signals elevator to moveSignals elevator to move Opens, signals person to exit, signals person to enterOpens, signals person to exit, signals person to enter None in problem statementNone in problem statement None in problem statementNone in problem statement
2424
Class Diagram with attributes and Class Diagram with attributes and operationsoperations
2525
Sequence DiagramsSequence Diagrams
Models steps that the controlling class Models steps that the controlling class repeatsrepeats
Focuses on how messages are sent among Focuses on how messages are sent among objects over timeobjects over time
2626
Each object is a rectangleEach object is a rectangleThe dashed line is the “lifeline” of the objectThe dashed line is the “lifeline” of the objectThe arrows are messages between objectsThe arrows are messages between objectsThe message invokes the corresponding operation in the receiving object.The message invokes the corresponding operation in the receiving object.The dashed line represents the value returned by the objectThe dashed line represents the value returned by the objectThe text to the far left is the constraint the sequence operates underThe text to the far left is the constraint the sequence operates under
In sum:In sum:Building sends a tick message to ClockBuilding sends a tick message to ClockBuilding sends a getTime message to clockBuilding sends a getTime message to clockClock returns time to BuildingClock returns time to BuildingBuilding sends a processTime message to Scheduler, passing the current time (the Scheduler must decide whether to create a person)Building sends a processTime message to Scheduler, passing the current time (the Scheduler must decide whether to create a person)At this point, and before the Building sends a processTiome message to the elevator, lots of things happen a shown on the next slideAt this point, and before the Building sends a processTiome message to the elevator, lots of things happen a shown on the next slide
2727
The bar on the edge of the The bar on the edge of the Scheduler bar is what happens Scheduler bar is what happens when an object sends a message to when an object sends a message to itself (delayTime(floor1))itself (delayTime(floor1))
If occupied is false, the scheduler If occupied is false, the scheduler creates an instance of class Person creates an instance of class Person
2828
Interactions Among ObjectsInteractions Among Objects
When two objects interactWhen two objects interact– A message sent by one objectA message sent by one object– Invokes an operation in another objectInvokes an operation in another object
2929
Interactions IInteractions ISenderSender MessageMessage ReceiverReceiver
ElevatorElevator resetButtonresetButton ElevatorButtonElevatorButtonringBellringBell BellBellelevatorArrivedelevatorArrived FloorFlooropenDooropenDoor DoorDoor
closeDoorcloseDoor DoorDoor
ClockClock
SchedulerScheduler stepOntoFloorstepOntoFloor PersonPersonisOccupiedisOccupied FloorFloor
PersonPerson pressButtonpressButton FloorButtonFloorButtonpressButtonpressButton ElevatorButtonElevatorButtonpassengerEnterspassengerEnters ElevatorElevatorpassengerExitspassengerExits ElevatorElevatorpassengerArrivespassengerArrives FloorFloor
FloorFloor resetButtonresetButton FloorButtonFloorButtonturnOffturnOff LightLightturnOnturnOn LightLight
3030
Interactions IIInteractions II
SenderSender MessageMessageReceiverReceiver
FloorButtonFloorButton summonElevatorsummonElevator ElevatorElevator
ElevatorButtonElevatorButton prepareToLeaveprepareToLeave ElevatorElevator
DoorDoor exitElevatorexitElevator PersonPerson
enterElevatorenterElevator PersonPerson
BellBell
LightLight
BuildingBuilding ticktick ClockClock
getTimegetTime ClockClock
processTimeprocessTime SchedulerScheduler
processTimeprocessTime ElevatorElevator
3131
Collaboration DiagramCollaboration Diagram
A collaboration consists of a collection of A collaboration consists of a collection of objects that work together to perform a task. objects that work together to perform a task.
Interacting objects are connected with solid Interacting objects are connected with solid lineslines
Objects pass messages along these lines in Objects pass messages along these lines in a direction indicated by arrows.a direction indicated by arrows.
A sequence of messages proceeds in A sequence of messages proceeds in numerical order.numerical order.
3232
1.1. Elevator sends resetButton message to Elevator ButtonElevator sends resetButton message to Elevator Button2.2. Elevator rings bellElevator rings bell3.3. Elevator sends arrival message to floorElevator sends arrival message to floor
1.1. Floor sends reset button messageFloor sends reset button message2.2. Floor sends turn on light messageFloor sends turn on light message
4.4. Elevator sends openDoor message to DoorElevator sends openDoor message to Door1.1. Door sends exitElevator message to passengerDoor sends exitElevator message to passenger
1.1. Person sends passengerExit message to ElevatorPerson sends passengerExit message to Elevator2.2. Door sends enterElevator message to waiting personDoor sends enterElevator message to waiting person
1.1. Passenger sends passengerEnters message to ElevatorPassenger sends passengerEnters message to Elevator
3333
Indicating public (+) and private (-)Indicating public (+) and private (-)
3434
Header Files (First Pass)Header Files (First Pass)
BuildingBuilding Elevator ButtonElevator Button
BellBell ElevatorElevator
LightLight SchedulerScheduler
DoorDoor PersonPerson
ClockClock
FloorFloor
Floor ButtonFloor Button
3535
InheritanceInheritance
We have a Class Crypto and two sub-classes We have a Class Crypto and two sub-classes derived from Crypto: Monoalphabetic and derived from Crypto: Monoalphabetic and Polyalphabetic. We represent the structure Polyalphabetic. We represent the structure in UML like this:in UML like this:
Crypto
Monoalphabetic Polyalphabetic