08 - Uml
08 - Uml
What is UML?
Examples:
• System: Aircraft
• Models: Flight simulator, scale model
• Views: All blueprints, electrical wiring, fuel system
Systems, Models and Views
Flightsimulator
Blueprints
Aircraft
Model 2
View 2
View 1
System
View 3
Model 1
Electrical
Wiring
Scale Model
UML Models, Views, Diagrams
• Use Cases
– Capture requirements
• Domain Model
– Capture process, key classes
• Design Model
– Capture details and behaviors of use cases and domain objects
– Add classes that do the work and define the architecture
UML Baseline
PurchaseTicket
Passenger
Actors
• Participating actors
• Entry conditions
• Flow of events
• Exit conditions
• Special requirements
Use Case Diagram: Example
Exceptional cases!
The <<extends>> Relationship
• <<extends>> relationships
represent exceptional or Passenger
seldom invoked cases.
• The exceptional event flows
are factored out of the main
event flow for clarity. PurchaseTicket
• Use cases representing
exceptional flows can extend <<extends>>
more than one use case.
• The direction of a <<extends>>
<<extends>> relationship is to <<extends>>
the extended use case OutOfOrder TimeOut
<<extends>>
Cancel NoChange
The <<includes>> Relationship
CollectMoney
<<extends>> <<extends>>
NoChange Cancel
Use Cases are useful to…
• Determining requirements
– New use cases often generate new requirements as the system is
analyzed and the design takes shape.
• Communicating with clients
– Their notational simplicity makes use case diagrams a good way for
developers to communicate with clients.
• Generating test cases
– The collection of scenarios for a use case may suggest a suite of test
cases for those scenarios.
Use Case Diagrams: Summary
TariffSchedule
Table zone2price
Enumeration getZones()
Name Price getPrice(Zone)
TariffSchedule
zone2price Attributes Signature
getZones()
getPrice()
Operations TariffSchedule
Instances
tarif_1974:TariffSchedule
zone2price = {
{‘1’, .20},
{‘2’, .40},
{‘3’, .60}}
UML Class Notation
• A class is a rectangle divided into three parts Employee
– Class name
-Name : string
– Class attributes (i.e. data members, variables)
– Class operations (i.e. methods) +ID : long
• Modifiers #Salary : double
– Private: - +getName() : string
– Public: + +setName()
– Protected: # -calcInternalStuff(in x : byte, in y : decimal)
– Static: Underlined (i.e. shared among all members of the class)
• Abstract class: Name in italics
UML Class Notation
• Lines or arrows between classes indicate relationships
– Association
• A relationship between instances of two classes, where one class must know about the other to
do its work, e.g. client communicates to server
• indicated by a straight line or arrow
– Aggregation
• An association where one class belongs to a collection, e.g. instructor part of Faculty
• Indicated by an empty diamond on the side of the collection
– Composition
• Strong form of Aggregation
• Lifetime control; components cannot exist without the aggregate
• Indicated by a solid diamond on the side of the collection
– Inheritance
• An inheritance link indicating one class a superclass relationship, e.g. bird is part of mammal
• Indicated by triangle pointing to superclass
Binary Association
myB.service(); myA.doSomething();
Employee
Team
-Name : string
-members : Employee +ID : long
1 #Salary : double
-adfaf : bool
*
+getName() : string
+setName()
-calcInternalStuff(in x : byte, in y : decimal)
members[0] =
new Employee();
… Filled diamond on
delete members[0]; side of the Collection
Inheritance
Standard concept of inheritance
Base Class
Derived Class
Multiplicities Meaning
Links on associations to specify more details about the relationship
zero or one instance. The notation n . . m indicates n to m
0..1
instances.
1 # Salary : double
- adfaf : bool
*
+ getName () : string
+ setName ()
- calcInternalStuff ( in x : byte , in y : decimal )
Static vs. Dynamic Design
• Format is
– Instance name : Class name
– Attributes and Values
– Example:
Objects and Links
Actor from
Use Case Objects
2
Activation 3
Shows Destruction of b
(and Construction)
Sequence Diagram : Timing
• When the alarm goes off, it rings the alarm, puts a message on
the display, notifies the monitoring service
Sequence Diagram Example
Hotel Reservation
Summary and Tools
• Time to practices