3. UML Diagrams
• UML recognizes 13 diagram types, although
most users of UML make do using three or four
types of diagram, depending on what they are
using it for.
4. UML Diagrams
• UML recognizes 13 diagram types, although
most users of UML make do using three or four
types of diagram, depending on what they are
using it for.
5. UML class diagrams
5
UML class diagram: a picture of the classes in an OO
system, their fields and methods, and connections
between the classes that interact or inherit from each
other details of how the classes interact with each other
algorithmic details; how a particular behavior is
implemented.
6. Diagram of one class
• class name in top of box
– write <<interface>> on top of interfaces' names
– use italics for an abstract class name
• attributes (optional)
– should include all fields of the object
• operations / methods (optional)
– may omit trivial (get/set) methods
• but don't omit any methods from an interface!
– should not include inherited methods
6
7. Class attributes
• attributes (fields, instance variables)
– visibility name : type [count] = default_value
– visibility: + public
# protected
- private
~ package (default)
/ derived
– underline static attributes
– derived attribute: not stored, but can
be computed from other attribute values
– attribute example:
- balance : double = 0.00
7
8. Class operations / methods
• operations / methods
– visibility name (parameters) : return_type
– visibility: + public
# protected
- private
~ package (default)
– underline static methods
– parameter types listed as (name: type)
– omit return_type on constructors and
when return type is void
– method example:
+ distance(p1: Point, p2: Point): double
8
9. Comments
• represented as a folded note, attached to the
appropriate class/method/etc by a dashed line
9
10. Relationships btwn. classes
• generalization: an inheritance relationship
– inheritance between classes
– interface implementation
• association: a usage relationship
– dependency
– aggregation
– composition
10
11. Generalization relationships
• Generalization (Inheritance) Relationships
– Hierarchies Drawn Top-down With Arrows
Pointing Upward To Parent
– Line/Arrow Styles Differ, Based On Whether
Parent Is A(n):
• Class:
Solid Line, Black Arrow
• Abstract Class:
Solid Line, White Arrow
• Interface:
Dashed Line, White Arrow
– We Often Don't Draw Trivial / Obvious
Generalization Relationships, Such As Drawing
The Object Class As A Parent
11
12. Associational relationships
• Associational (Usage) Relationships
1. Multiplicity (How Many Are Used)
• * 0, 1, Or More
• 1 1 Exactly
• 2..4 Between 2 And 4, Inclusive
• 3..* 3 Or More
2. Name (What Relationship The Objects Have)
3. Navigability (Direction)
12
13. Multiplicity of associations
13
one-to-one
each student must carry exactly one ID card
one-to-many
one rectangle list can contain many rectangles
15. Class diagram example 2
15
DVD Movie VHS Movie Video Game
Rental Item
Rental Invoice
1..*
1
Customer
Checkout Screen
0..1
1
Simple
Association
Class
Abstract
Class
Simple
Aggregation
Generalization
Composition
Multiplicity
16. Class diagram example 3
16
StudentBody
+ main (args : String[])
+ toString() : String
1 100
Student
- firstName : String
- lastName : String
- homeAddress : Address
- schoolAddress : Address
+ toString() : String
- streetAddress : String
- city : String
- state : String
- zipCode : long
Address
17. Class design exercise
• Consider this Texas Hold 'em poker game system:
– 2 to 8 human or computer players
– Each player has a name and stack of chips
– Computer players have a difficulty setting: easy, medium,
hard
– Summary of each hand:
• Dealer collects ante from appropriate players, shuffles
the deck, and deals each player a hand of 2 cards from
the deck.
• A betting round occurs, followed by dealing 3 shared
cards from the deck.
• As shared cards are dealt, more betting rounds occur,
where each player can fold, check, or raise.
• At the end of a round, if more than one player is
remaining, players' hands are compared, and the best
hand wins the pot of all chips bet so far. 17
18. Class design exercise
– Draw a class diagram for this system. Include
relationships between classes (generalization and
associational).
18
19. UML Modeling Behavior
19
Use Case: a picture of the classes in an OO system, their
fields and methods, and connections between the
classes that interact or inherit from each other details of
how the classes interact with each other algorithmic
details; how a particular behavior is implemented.
20. Use Cases
• The use case is a summary of scenarios for a
single task or goal.
• So What is the Use Case????
• The Use Case is Make Appointment.
• It is a use case for the medical clinic.
21. Use Cases
• The picture below is a Make Appointment use case for
the medical clinic.
• The actor is a Patient. The connection between actor and
use case is a communication association (or
communication for short).
Actors are stick figures. Use cases are ovals. Communications are lines that
link actors to use cases.
22. Use Case Components
• The use case has three components.
• The use case task referred to as the use case that
represents a feature needed in a software system.
• The actor(s) who trigger the use case to activate.
• The communication line to show how the actors
communicate with the use case.
23. Use Case Diagram - Use Case
• A major process performed by the system that
benefits an actor(s) in some way
• Models a dialogue between an actor and the system
• Represents the functionality provided by the system
24. Use Case
• Each use case in a use case diagram describes one
and only one function in which users interact with
the system
– May contain several “paths” that a user can take
while interacting with the system
– Each path is referred to as a scenario
25. Use Case
• Labelled using a descriptive verb-noun phrase
• Represented by an oval
Make
Appointment
Make
Appointment
26. Use Case - Actor
• Labelled using a descriptive noun or phrase
• Represented by a stick character
27. Use Case - Relationships
• Relationships
– Represent communication between actor and use
case
– Depicted by line or double-headed arrow line
– Also called association relationship
Make
Appointment
28. Use Case - Relationships
• Boundary
– A boundary rectangle is placed around the perimeter
of the system to show how the actors communicate
with the system.
Make
Appointment
29. Guidelines for Creating
Use-Case Diagrams
– Order messages from left to right, top to bottom
• Name actors and objects the same if they represent the
same idea
• Place the initiator of the scenario on the left of the
diagram
• Multiple objects of the same class: name each
• Only show return values when they are not obvious
• Justify messages near the arrowhead for improved
readability
30. Use-Case Diagram
A use case diagram is a collection of actors, use cases, and their communications.
32. State Machine
Software Design (UML)
• An object must be in some specific state at any given time
during its lifecycle.
• An object transitions from one state to another as the
result of some event that affects it.
• You may create a state diagram for any class,
collaboration, operation, or use case in a UML model .
• There can be only one start state in a state diagram, but
there may be many intermediate and final states.
34. Components of State Machines
• States—values of an object’s attributes at a point in
time
• Events—the cause of the change in values of the
object’s attributes
• Transitions—movement of an object from one state
to another
– May include a guard condition to flag that a condition is true and
allow the transition
36. State Machine
Software Design (UML)
selecting
verifying
downloading
checking schedule
download course offerings
make a course selection
verify selection
check schedule
select another course
make a different selection
unscheduled
scheduled
sign schedule
37. Guidelines for Creating Behavioral State
Machines
• Use only for complex objects
• Draw the initial state in the upper left corner
• Draw the final state in the bottom right corner
• Use simple, but descriptive names for states
• Look out for “black holes” and “miracles”
• Ensure guard conditions are mutually exclusive
• Ensure transitions are associated with messages
and operations
38. Building a Behavioral State Machine
• Set the context
• Identify the states of the object
• Initial
• Final
• Stable states during its lifetime
• Lay out the diagram—use a left to right sequence
• Add the transitions
• Identify the triggers (events that cause the transition)
• Identify the actions which execute
• Identify the guard conditions
• Validate the model—ensure all states are reachable
39. UML Modeling Behavior
39
Sequence Diagram: Sequence Diagram is a diagram that
depicts object interactions arranged in time sequence,
where the direction of time is down the page. The
objects, which exchange information, are shown at the
top of a vertical line or bar, known as the object’s
lifeline. An arrow between the lifelines of two objects
represents each message.
42. Sequence Diagram
Software Design (UML)
An object in a sequence diagram is rendered
as a box with a dashed line descending from it.
The line is called the object lifeline, and it
represents the existence of an object over a
period of time.
an Order Line
43. Sequence Diagram
Software Design (UML)
an Order Line a Stock Item
[check = “true”]
remove()
check()
Messages are rendered as horizontal
arrows being passed from object to
object as time advances down the
object lifelines. Conditions ( such as
[check = “true”] ) indicate when a
message gets passed.
44. Sequence Diagram
Software Design (UML)
an Order Line a Stock Item
[check = “true”]
remove()
check()
Notice that the bottom arrow is different. The arrow
head is not solid, and there is no accompanying
message.
This arrow indicates a return from a previous
message, not a new message.
45. Sequence Diagram
Software Design (UML)
an Order a Order Line
* prepare()
An iteration marker, such as * (as shown), or *[i
= 1..n] , indicates that a message will be
repeated as indicated.
Iteration
marker
48. Building Sequence Diagrams
• Set the context
• Identify actors and objects that interact in the use-case
scenario
• Set the lifeline for each object
• Add messages by drawing arrows
• Shows how they are passed from one object to
another
• Include any parameters in parentheses
• Obvious return values are excluded
• Add execution occurrence to each object’s lifeline
• Validate the sequence diagram
• Ensures that it depicts all of the steps in the process
This allows information to be omitted from any diagram in order to make it easier to understand.
The corollary is that you should never infer anything from the absence of information
in a diagram and that UML diagrams should not be read on their own without access
to the rest of the model.
This allows information to be omitted from any diagram in order to make it easier to understand.
The corollary is that you should never infer anything from the absence of information
in a diagram and that UML diagrams should not be read on their own without access
to the rest of the model.
Use Case
Represent the user functionality (not system functionality)
Use Case
In reading a use case, you should not be able to tell if an activity is computerized or manual
Used to document the current system (AS-IS system) or the new system being developed (TO-BE system)
Communicates at a high level what the system needs to do
Captures the typical interaction of the system with the system’s users
Logical model
Physical details are defined during the design phase
Use case: A use case in a use case diagram is a visual representation of a distinct business functionality in a system. The key term here is "distinct business functionality." To choose a business process as a likely candidate for modeling as a use case, you need to ensure that the business process is discrete in nature. As the first step in identifying use cases, you should list the discrete business functions in your problem statement. Each of these business functions can be classified as a potential use case. Remember that identifying use cases is a discovery rather than a creation. As business functionality becomes clearer, the underlying use cases become more easily evident. A use case is shown as an ellipse in a use case diagram Depicted by an oval
MUST label the oval with the name of the use case
Actors: An actor portrays any entity (or entities) that performs certain roles in a given system. The different roles the actor represents are the actual business roles of users in a given system. An actor in a use case diagram interacts with a use case. For example, for modeling a banking application, a customer entity represents an actor in the application. Similarly, the person who provides service at the counter is also an actor. But it is up to you to consider what actors make an impact on the functionality that you want to model. If an entity does not affect a certain piece of functionality that you are modeling, it makes no sense to represent it as an actor. An actor is shown as a stick figure in a use case diagram depicted "outside" the system boundary, as shown in Make Appointment figure.
Depicted by an oval
MUST label the oval with the name of the use case
To identify an actor, search in the problem statement for business terms that portray roles in the system. For example, in the statement "patients visit the doctor in the clinic for medical tests," "doctor" and "patients" are the business roles and can be easily identified as actors in the system.
Use Case Relationship
Association relationship
May exist between actor and a use case
Often referred to as a communicate association
Navigable in both directions (actor to use case and use case to actor)
Some use just a line
Others use a double-headed arrowhead
Navigable in only one direction (actor to use case OR use case to actor)
Use a arrowhead where arrowhead denotes the direction of communication
Navigation direction of an association represents who is initiating the communication
Multiplicity
Not consistency shown on all use-case diagrams (Some do; some don’t)
System boundary: A system boundary defines the scope of what a system will be. A system cannot have infinite functionality. So, it follows that use cases also need to have definitive limits defined. A system boundary of a use case diagram defines the limits of the system. The system boundary is shown as a rectangle spanning all the use cases in the system.
Other use cases in this lecture also show the system boundary of the clinic application. The use cases of this system are enclosed in a rectangle. Note that the actors in the system are outside the system boundary.
The system boundary is potentially the entire system as defined in the problem statement. But this is not always the case. For large and complex systems, each of the modules may be the system boundary. For example, for an ERP system for an organization, each of the modules such as personnel, payroll, accounting, and so forth, can form the system boundary for use cases specific to each of these business functions. The entire system can span all of these modules depicting the overall system boundary.
Example Use Case
ACTORS
Represented by a stick figure
named
USE CASE
Represented by an oval
Named (POORLY NAMED; should be verb phrase)
RELATIONSHIP
2-way association
System Boundary
Use cases are enclosed within a system boundary
a box that represents the system and clearly delineates what parts of the diagram are external or internal to it
Name of the system can appear inside or on top of the box