Académique Documents
Professionnel Documents
Culture Documents
1
Use cases and Actors Example: Staff Management
Add new Staff
staff member Management
• Use case: System
– a pattern of behavior that the new system is required Add new
to exhibit staff category
– a sequence of related actions performed by an actor
and the system via a dialogue. Change rate
for staff category
• Actor:
Accountant
– anything that needs to interact with the system: Change category
• a person for staff member
<<extends>> <<uses>>
When one use case adds behaviour to a base case One use case invokes another (like a procedure call);
– used to model a part of a use case that the user may see as – used to avoid describing the same flow of events several times
optional system behavior;
– puts the common behavior in a use case of its own.
– also models a separate sub-case which is executed conditionally.
Swipe UPC
Distribute schedule code
info to students
CSC340 University of Toronto 7 CSC340 University of Toronto 8
2
Example: Car Example: Meeting Scheduler
Driver GasAttendant Mechanic
Initiator Participant
<<uses>> <<uses>>
Fill Up Check Oil Fix Car Edit <<extends>> Provide
Generate Withdraw constraints
Drive Schedule Constraints
Schedule
< < us
<<uses>> meeing
>>
<<uses>> <<extends>>
es
us
<<
es>>
<<uses>> Turn On
<<
us
Fix car on
Engine >>
es
the road ses
<<u
>>
Validate
User
3
Generalizations UML Sequence Diagrams
Generalization relations: “is a” • Actor classes
– It’s sometimes useful to identify
classes of actor • Describe a Use Case using Sequence Diagrams
• E.g. where several actors belong
to a single class – Sequence diagrams show step-by-step what’s
• Some use cases are needed by
all members in the class
involved in a use case
• Other use cases are only needed • Which objects are relevant to the use case
by some members of the class • How those objects participate in the function
– Actors inherit use cases from
the class – You may need several sequence diagrams to
• Use Case classes describe a single use case.
– Sometimes useful to identify a • Each sequence diagram describes one possible scenario for
generalization of several use
cases the use case
– Sequence diagrams…
• …should remain easy to read and understand.
• …do not include complex control logic
Example: Place
book order Example: Calculate staff bonuses
Place book order Customer
Customer Customer Invokes
initiates the the search method iteration
sequence in OnlineStore
:Accountant :PayrollSystem :Staff :Bank
4
Example: Add an advertisement Modelling Sequences of Events
• Objects “own” information and behaviour
– Objects don’t “know” about other objects’
information, but can ask for it.
– To carry out business processes, objects
have to collaborate.
• …by sending messages to one another to invoke
each others’ operations
– Objects can only send messages to one
another if they “know” each other
• I.e. if there is an association between them.
Decision
CSC301 University of Toronto 19 CSC301 University of Toronto 20
5
Example 3: Order System
Example 2: Order System
(with loop)
Receive Guard Receive
[failed] [failed]
Order Cancel Order Order Cancel Order
Authorize Authorize
Payment Decision Payment
[succeeded] [succeeded]
Assign Items Dispatch Order Assign Item Dispatch Order
to Order * [for each to Order
Fork item in order]
Join
6
Example 3: Diagram with Swimlanes Classes
Customer Sales Warehouse
• A class describes a group of objects with
– similar properties (attributes),
Request – common behaviour (operations),
Product – common relationships to other objects,
– and common meaning (“semantics”).
Process Line Item Pull Materials • Example:
– Employee: has a name, employee number and department;
Ship Order an employee is hired, and fired; an employee works on one
or more projects
:Employee
name Name (mandatory)
Receive Order Attributes
Bill Customer (optional) employee number
department
hire
Add Remainder fire Operations
Pay Bill Close Order
to Stock
[BRJ99] works on projects (optional)
CSC301 University of Toronto 25 CSC301 University of Toronto 26
7
Class Associations Association Multiplicity
Multiplicity Multiplicity
A Client has A StaffMember is
Name assigned zero or
exactly one StaffMember of the more Clients • Multiplicity: the minimum and maximum
as a contact person
association
times an object can be associated with the
:Client related object
:StaffMember
company name
name 1 assigned to 0..* mailing address • Examples:
id number email
start date contact fax – Optional (0 or 1) 0..1
person phone
– Exactly one 1 = 1..1
Direction – Zero or more 0..*
The “assigned to”
association should be – One or more 1..*
Role read in this direction – A range of values 1..6
The StaffMember’s
role in this association
– A set of ranges 1..3,7..10,15,19..*
is as a contact person
CSC301 University of Toronto 29 CSC301 University of Toronto 30
8
Aggregation Composition
The “is part of” or “whole-part” relationship • Strong form of aggregation that implies ownership:
– if the whole is removed from the model, so is the part
– the whole is responsible for the disposition of its parts
An employee is part of a team.
:Team :Employee
:Car :Engine
0..* 1..*
1 1
9
More on Generalization [2] Finding Classes
• Don’t generalize just for the sake of it • Look for nouns and noun phrases in
– Be sure that everything about the superclass stakeholders’ descriptions of the problem
applies to the subclasses – include in the model if they explain the nature
or structure of information in the application.
– Be sure that the superclass is useful as a
class in its own right • It’s better to include many candidate
– Don’t add subclasses or superclasses that are
classes at first
not relevant to your analysis – You can always eliminate them later if they
turn out not to be useful
– Explicitly deciding to discard classes is better
than just not thinking about them
CSC301 University of Toronto 37 CSC301 University of Toronto 38
10
Coad & Yourdon’s Criteria
Selecting Classes
for Selecting Classes
• Discard classes for concepts which: • Retained information: Will the system need to
remember information about this class of objects?
– Are beyond the scope of the analysis • Needed Services: Do objects in this class have
– Refer to the system as a whole identifiable operations that change the values of their
– Duplicate other classes attributes?
• Multiple Attributes: Does the class have multiple
– Are too vague or too specific attributes?
• e.g. have too many or too few instances • Common Attributes: Does the class have attributes that
• Include external entities as classes if they: are shared with all instances of its objects?
– Produce or consume information essential to • Common Operations: Does the class have operations
that are shared with all instances of its objects?
the system
[Pre97]
CSC301 University of Toronto 41 CSC301 University of Toronto 42
[Mac01]
CSC301 University of Toronto 43 CSC301 University of Toronto 44
11
Abstraction Exercise: Abstraction
For each state, what are the properties or value ranges of
• The state space of most objects is enormous
initialBalance and currentBalance that interest us?
– State space size is the product of the range of each attribute
5
• E.g. object with five boolean attributes: 2 +1 states
5
• E.g. object with five integer attributes: (maxint) +1 states initialBalance > currentBalance
• E.g. object with five real-valued attributes: …?
:Invoice partialPayment()
– If we ignore computer representation limits, the state space is
infinite initialBalance
partialPayment()
• Only part of that state space is “interesting” currentBalance unpaid partially paid
– Some states are not reachable partialPayment()
– Integer and real values usually only vary within some relevant finalPayment() finalPayment()
range finalPayment()
– Often not interested in the actual values, just certain ranges: fully paid
• Example for Age: age<18, 18≤age≤65, age>65
• Example for Cost: cost ≤ budget, cost==0, cost > budget, initialBalance == currentBalance
cost > (budget+10%)
currentBalance == 0
Transitions : CourseRegistration
maxCapacity
Transitions [2]
currCapacity
A transition consists of three parts: enrollmentStatus event [guard] / action
classList • A guard is a Boolean condition that must be
event [guard] / action addStudent()
true in order for a transition to “fire”.
removeStudent()
openEnrollment() – When an event occurs the guard conditions
closeEnrollment() are checked, and if they are met, then the
• A transition is the movement from one state to another. printClassList() transition fires.
• States are either “on” or “off” at a given point in time. • The action is a procedural expression to be
performed when the transition fires.
• If a state is on, then transitions from it are enabled. addStudent() [currCapacity < = maxCapacity]
action
• Transitions are triggered by events. closeEnrollment()/ printClassList
space available
partialPayment()
12
Events Events [2]
• Call events occur when an object receives a call for one • Change events occur when a condition becomes true
of its operations to be performed – denoted by the keyword ‘when’
– Example: Bill class
– Example: Invoice class
payBalance()
when: [ currentBalance == 0]
unpaid paid
unpaid paid
• Signal events occur when an object receives an explicit • Time events mark the passage of a designated period of
(real-time) signal time
– Example signal: Mouse click
– Example: Exam class
– More useful in design after: [3 hours]
– Syntax is the same as call events in progress complete
13
Class Diagrams and Statecharts Style Tips
• Consistency Checks between diagrams • The diagram should have start and end state(s).
• Diagrams are usually read from top-left to bottom-right,
– Each statechart should correspond to one so put the start and end states in those locations.
class on the Class diagram. • Each state should have at least one transition into it and
– All events in a statechart should appear as: at least one transition out of it.
• The diagram should be deterministic.
• operations (methods) of an appropriate class in the
class diagram • Use a superstate when multiple states have a common
entry or exit condition.
– All actions in a statechart should appear as: • It is fine for guards on transitions from a state to not form
• operations (methods) of an appropriate class in the a complete set.
class diagram [Amb03]
14
Relationships Examples
• Logical links between two or more entities. Student Writes Exam
– E.g. Resides is a relationship that can exist between
a City entity and a Person entity
• An instance of a relationship is an n-tuple of
instances of entities
Manages
– E.g. the pair (Johanssen,Stockholm), is an instance
in the relationship Resides.
• Usually described using verbs (sometimes Employee Department
nouns)
WorksIn
Meets Resides Owns
15
Example: Instances for Owns Meaning of ER Diagrams
Course Meets Room
o1
P1 • Course and Room are entities.
o2 C1 – Their instances are particular courses (eg CSC340S) and rooms
o3 (eg BA1130)
P2 • Meets is a relationship.
P3 C2 – Its instances describe particular meetings.
o4 – Each meeting has exactly one associated course and room
P4
o5 C3
P5 o6
16
Cardinalities of Attributes Cardinalities of Attributes [2]
• Attributes can also have cardinalities • Multi-valued attribute surname LicenceNumber
– To describe the minimum and maximum number of values of the cardinalities are
attribute associated with each instance of an entity or a problematic
relationship. – Usually better Person
– The default is (1,1) modelled with
additional entities (0,N)
– Optional attributes have cardinality (0,1) linked by one-to-many
(or many-to-many) Owns
CarRegistration relationships
(0,N) (1,1)
CarRegistration
surname
Registration
17
Ternary Relationships Generalizations
• Show “is-a” relationships between entities
age
surname taxCode address taxCode
Person Professional
maternityStatus specialization
• Inheritance:
– Every instance of a child entity is also an instance of the parent entity
– Every property of the parent entity (attribute, identifier, relationship or
other generalization) is also a property of a child entity
18