Download presentation
Presentation is loading. Please wait.
1
UML Review
2
Overview: modeling with UML
What is modeling? What is UML? Use case diagrams Class diagrams Sequence diagrams Activity diagrams Statechart diagrams
3
What is modeling? Modeling consists of building an abstraction of reality. Abstractions are simplifications because: They ignore irrelevant details and They only represent the relevant details. What is relevant or irrelevant depends on the purpose of the model.
4
Why model software? Software is getting increasingly more complex
Windows XP > 40 mio lines of code A single programmer cannot manage this amount of code in its entirety. Code is not easily understandable by developers who did not write it We need simpler representations for complex systems Modeling is a mean for dealing with complexity
5
What is UML? UML (Unified Modeling Language)
An emerging standard for modeling object-oriented software. Resulted from the convergence of notations from three leading object-oriented methods: OMT (James Rumbaugh) OOSE (Ivar Jacobson) Booch (Grady Booch) Reference: “The Unified Modeling Language User Guide”, Addison Wesley, 1999. Supported by several CASE tools Rational ROSE TogetherJ
6
UML Core Conventions Rectangles are classes or instances
Ovals are functions or use cases Instances are denoted with an underlined names myWatch:SimpleWatch Joe:Firefighter Types are denoted with non underlined names SimpleWatch Firefighter Diagrams are graphs Nodes are entities Arcs are relationships between entities
7
Use Case Diagrams Passenger PurchaseTicket
Used during requirements elicitation to represent external behavior Actors represent roles, that is, a type of user of the system Use cases represent a sequence of interaction for a type of functionality The use case model is the set of all use cases. It is a complete description of the functionality of the system and its environment Passenger PurchaseTicket
8
Actors An actor models an external entity which communicates with the system: User External system Physical environment An actor has a unique name and an optional description. Examples: Passenger: A person in the train GPS satellite: Provides the system with GPS coordinates Passenger
9
Use Case A use case represents a class of functionality provided by the system as an event flow. A use case consists of: Unique name Participating actors Entry conditions Flow of events Exit conditions Special requirements PurchaseTicket
10
System Boundary Passenger PurchaseTicket
TicketSystem Passenger PurchaseTicket A system boundary rectangle separates the ticket system from the external actors
11
The <<extends>> Relationship
<<extends>> relationships represent exceptional or seldom invoked cases. The exceptional event flows are factored out of the main event flow for clarity. Use cases representing exceptional flows can extend more than one use case. The direction of a <<extends>> relationship is to the extended use case Passenger PurchaseTicket OutOfOrder <<extends>> Cancel <<extends>> TimeOut <<extends>> NoChange <<extends>>
12
The <<includes>> Relationship
Passenger <<includes>> relationship represents behavior that is factored out of the use case. <<includes>> behavior is factored out for reuse, not because it is an exception. The direction of a <<includes>> relationship is to the using use case (unlike <<extends>> relationships). PurchaseMultiCard PurchaseSingleTicket <<includes>> CollectMoney <<includes>> NoChange <<extends>> Cancel <<extends>>
13
Use Case Diagrams: Summary
Use case diagrams represent external behavior An Actor is a role of an object or objects outside of a system that interacts directly with it as part of a coherent work unit (a use case) <<includes>> and <<extends>> allow common fragments of use cases to be pulled out into a separate use cases <<includes>> is like a “use case subroutine” <extends>> is an alternative course of action
14
Class Diagrams TarifSchedule Trip Enumeration getZones() Price getPrice(Zone) zone:Zone Price: Price * * Class diagrams represent the structure of the system. Used during requirements analysis to model problem domain concepts during system design to model subsystems and interfaces during object design to model classes.
15
Classes Name Signature Attributes Operations
Table zone2price Enumeration getZones() Price getPrice(Zone) TarifSchedule Name zone2price getZones() getPrice() TarifSchedule Attributes Signature Operations TarifSchedule A class represent a concept A class encapsulates state (attributes) and behavior (operations). Each attribute has a type. Each operation has a signature. The class name is the only mandatory information.
16
tarif_1974:TarifSchedule
Instances tarif_1974:TarifSchedule zone2price = { {‘1’, .20}, {‘2’, .40}, {‘3’, .60}} An instance represents a phenomenon. The name of an instance is underlined and can contain the class of the instance. The attributes are represented with their values.
17
Associations * * Associations denote relationships between classes.
TarifSchedule TripLeg Enumeration getZones() Price getPrice(Zone) Price Zone * * Associations denote relationships between classes. The multiplicity of an association end denotes how many objects the source object can legitimately reference.
18
1-to-1 and 1-to-many Associations
Country capital name:String name:String One-to-one association Point * Polygon x: Integer y: Integer draw() One-to-many association
19
Many-to-Many Associations
Lists * * Company StockExchange tickerSymbol * Lists 1 A stock exchange lists many companies each of them uniquely identifed by a ticker symbol used at that stock exchange. A company can be listed on more than one stock exchange, using the same ticker symbol. Mercedes Benz is an example for a company listed on more than one stock exchange: Frankfurt and NYSE. Does it have two different Ticker symbols? Something not clear here: What happens if the company cannot have the same ticker symbol on two different stock exchanges? Company StockExchange tickerSymbol SX_ID qualifier
20
From Problem Statement To Object Model
oblem Statement: A stock exchange lists many companies. Each company is uniquely identified by a ticker symbol Class Diagram: Company StockExchange * * Lists tickerSymbol
21
From Problem Statement to Code
: A stock exchange lists many companies. Each company is identified by a ticker Symbol Class Diagram: * * StockExchange Company Lists tickerSymbol Java Code public class StockExchange { private Vector m_Company = new Vector(); }; public class Company { public int m_tickerSymbol; private Vector m_StockExchange = new Vector(); };
22
Aggregation An aggregation is a special case of association denoting a “consists of” hierarchy. The aggregate is the parent class, the components are the children class. A solid diamond denotes composition, a strong form of aggregation where components cannot exist without the aggregate. Exhaust system Muffler diameter Tailpipe 1 0..2 Exhaust system 1 0..2 Muffler Tailpipe diameter diameter TicketMachine 3 ZoneButton
23
Inheritance Button ZoneButton CancelButton The children classes inherit the attributes and operations of the parent class. Inheritance simplifies the model by eliminating redundancy.
24
Class Relationships Our class diagram has three kinds of relationships. association -- a relationship between instances of the two classes. There is an association between two classes if an instance of one class must know about the other in order to perform its work. In a diagram, an association is a link connecting two classes. aggregation -- an association in which one class belongs to a collection. An aggregation has a diamond end pointing to the part containing the whole. In our diagram, Order has a collection of OrderDetails. generalization -- an inheritance link indicating one class is a superclass of the other. A generalization has a triangle pointing to the superclass. Payment is a superclass of Cash, Check, and Credit.
25
Composition and aggregation
Associations in which an object is part of a whole are aggregations. Composition is a strong association in which the part can belong to only one whole -- the part cannot exist without the whole. Composition is denoted by a filled diamond at the whole end. This diagram shows that a BoxOffice belongs to exactly one MovieTheater. Destroy the MovieTheater and the BoxOffice goes away! The collection of Movies is not so closely bound to the MovieTheater.
26
Without qualification
Qualifiers Directory File filename Without qualification 1 * With qualification Directory File 0…1 1 filename Qualifiers can be used to reduce the multiplicity of an association.
27
* * An example Account Amount Deposit() Withdraw() GetBalance()
CustomerId AccountId Bank Name Customer Name * * Has CustomerId Savings Account Withdraw() Checking Account Withdraw() Mortgage Account Withdraw()
28
UML sequence diagrams Used during requirements analysis
selectZone() pickupChange() pickUpTicket() insertCoins() Passenger TicketMachine Used during requirements analysis To refine use case descriptions to find additional objects (“participating objects”) Used during system design to refine subsystem interfaces Classes are represented by columns Messages are represented by arrows Activations are represented by narrow rectangles Lifelines are represented by dashed lines
29
Nested messages Dataflow
Passenger TarifSchedule Display ZoneButton selectZone() lookupPrice(selection) price Dataflow displayPrice(price) …to be continued... The source of an arrow indicates the activation which sent the message An activation is as long as all nested activations Horizontal dashed arrows indicate data flow Vertical dashed lines indicate lifelines
30
…continued from previous slide...
Iteration & condition Passenger …continued from previous slide... CoinIdentifier Display CoinDrop ChangeProcessor * insertChange(coin) lookupCoin(coin) price Iteration displayPrice(owedAmount) Condition [owedAmount<0] returnChange(-owedAmount) …to be continued... Iteration is denoted by a * preceding the message name Condition is denoted by boolean expression in [ ] before the message name
31
Creation and destruction
Passenger …continued from previous slide... ChangeProcessor Creation Ticket createTicket(selection) print() Destruction free() Creation is denoted by a message arrow pointing to the object. Destruction is denoted by an X mark at the end of the destruction activation. In garbage collection environments, destruction can be used to denote the end of the useful life of an object.
32
Sequence Diagram Summary
UML sequence diagram represent behavior in terms of interactions. Complement the class diagrams (which represent structure).
33
Represent behavior as states and transitions
State Chart Diagrams State Initial state Event Transition Final state Represent behavior as states and transitions
34
Activity Diagrams An activity diagram shows flow control within a system An activity diagram is a special case of a state chart diagram in which states are activities (“functions”)
35
Statechart Diagram vs. Activity Diagram
Statechart Diagram for Incident (similar to Mealy Automaton) (State: Attribute or Collection of Attributes of object of type Incident) Event causes State transition Active Inactive Closed Archived Incident- Documented Incident- Handled Incident- Archived Activity Diagram for Incident (similar to Moore (State: Operation or Collection of Operations) Triggerless Transition Completion of activity causes state transition
36
Activity Diagram: Modeling Decisions
37
Activity Diagrams: Modeling Concurrency
Synchronization of multiple activities Splitting the flow of control into multiple threads Splitting Synchronization
38
Activity Diagrams: Swimlanes
Actions may be grouped into swimlanes to denote the object or subsystem that implements the actions. Dispatcher Allocate Resources Open Coordinate Archive Incident Resources Incident FieldOfficer Document Incident
39
UML Summary UML provides a wide variety of notations for representing many aspects of software development Powerful, but complex language Can be misused to generate unreadable models Can be misunderstood when using too many exotic features For now we concentrate on a few notations: Functional model: Use case diagram Object model: class diagram Dynamic model: sequence diagrams, statechart and activity diagrams
40
Problems with UML Semi-formal
Go directly to the class/objects – a low level. Not good at express temporal information – StateChart
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.