08 class and sequence diagrams
DESCRIPTION
TRANSCRIPT
![Page 1: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/1.jpg)
INTROSE Introduction to Software Engineering
Raymund Sison, PhDCollege of Computer Studies
De La Salle University
Modeling Software Systems
![Page 2: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/2.jpg)
How do we model complex systems?Epistemology
Knowledge about Causality
(Dynamic Model)
Describes our knowledge about the system
Knowledge about Functionality(Functional model)
Knowledge about Relationships(Object model)
Neural Networks
DataFlow Diagrams (SA/SD)
Scenarios/Use Cases(Jacobsen)
Formal Specifications
(Liskov)
Petri Nets(Petri)Inheritance
Frames,SemanticNetworks (Minsky)
Uncertain KnowledgeFuzzy Sets (Zadeh)
Data Relationship(E/R Modeling, Chen)
Hierarchical Database
Model (IMS)
NetworkDatabase
Model(CODASYL)
RelationalDatabase Model
(Codd)
Fuzzy Frames(Graham)
Class Diagrams(“E/R + Inheritance”,
Rumbaugh)
Sequence Diagrams(Lamport)Activity
Diagrams(“good old Flowcharts”)
From (Bruegge & Dutoit, 2004)
![Page 3: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/3.jpg)
How do we model complex systems?
Epistemology
Knowledge about Causality
(Dynamic Model)
Describes our knowledge about the system
Knowledge about Functionality(Functional model)
Knowledge about Relationships(Object model)
Neural Networks
DataFlow Diagrams (SA/SD)
Scenarios/Use Cases(Jacobsen)
Formal Specifications
(Liskov)
Petri Nets(Petri)Inheritance
Frames,SemanticNetworks (Minsky)
Uncertain KnowledgeFuzzy Sets (Zadeh)
Data Relationship(E/R Modeling, Chen)
Hierarchical Database
Model (IMS)
NetworkDatabase
Model(CODASYL)
RelationalDatabase Model
(Codd)
Fuzzy Frames(Graham)
Class Diagrams(“E/R + Inheritance”,
Rumbaugh)
Sequence Diagrams(Lamport)Activity
Diagrams(“good old Flowcharts”)
From (Bruegge & Dutoit, 2004)
![Page 4: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/4.jpg)
Components of an Object Model
ClassesAssociations (Relations) Kind-of/Is-a (Generalization) Part-of/Has-a (Aggregation) Domain-specific associations
AttributesOperations
![Page 5: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/5.jpg)
UML Classes
A class is simply represented as a box with the name of the class inside
The diagram may also show the attributes and operations
The complete signature of an operation is: operationName(parameterName: parameterType …): returnType
Class Diagram slides from (Lethbridge & Laganiere, 2005)
![Page 6: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/6.jpg)
Associations and Multiplicity
An association is used to show how two classes are related to each other
Symbols indicating multiplicity are shown at each end of the association
![Page 7: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/7.jpg)
Labelling Associations
Each association can be labelled, to make explicit the nature of the association
![Page 8: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/8.jpg)
Analyzing and Validating Associations
Many-to-one• A company has many employees,
• An employee can only work for one company. This company will not store data about the moonlighting
activities of employees!
• A company can have zero employees E.g. a ‘shell’ company
• It is not possible to be an employee unless you work for a company
*worksForEmployee Company1
![Page 9: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/9.jpg)
Analyzing and Validating Associations
Many-to-many• An assistant can work for many managers
• A manager can have many assistants
• Assistants can work in pools
• Managers can have a group of assistants
• Some managers might have zero assistants.
• Is it possible for an assistant to have, perhaps temporarily, zero managers?
*
supervisor
*****1..*Assistant Manager
![Page 10: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/10.jpg)
Analyzing and Validating Associations
One-to-one• For each company, there is exactly one board of
directors
• A board is the board of only one company
• A company must always have a board
• A board must always be of some company
Company BoardOfDirectors11
![Page 11: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/11.jpg)
Analyzing and Validating Associations
Avoid unnecessary one-to-one associations
Avoid this Do this
![Page 12: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/12.jpg)
A More Complex Example
A booking is always for exactly one passenger • no booking with zero passengers
• a booking could never involve more than one passenger.
A Passenger can have any number of Bookings• a passenger could have no bookings at all
• a passenger could have more than one booking
The frame around this diagram is an optional feature that any UML 2.0 may possess.
![Page 13: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/13.jpg)
Association Classes
Sometimes, an attribute that concerns two associated classes cannot be placed in either of the classes
The following are equivalent
![Page 14: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/14.jpg)
Reflexive Associations
It is possible for an association to connect a class to itself
![Page 15: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/15.jpg)
Directionality in Associations
Associations are by default bi-directional It is possible to limit the direction of an
association by adding an arrow at one end
![Page 16: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/16.jpg)
Generalization
Specializing a superclass into two or more subclasses
A generalization set is a labeled group of generalizations with a common superclass
The label (sometimes called the discriminator) describes the criteria used in the specialization
![Page 17: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/17.jpg)
Avoiding Unnecessary Generalizations
Inappropriate hierarchy ofclasses, which should beinstances
![Page 18: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/18.jpg)
Avoiding Unnecessary Generalizations
Improved class diagram, with its corresponding instance diagram
![Page 19: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/19.jpg)
Handling Multiple Discriminators
Creating higher-level generalization
![Page 20: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/20.jpg)
Handling Multiple Discriminators
Using multiple inheritance
![Page 21: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/21.jpg)
Object Diagrams
A link is an instance of an association (in the same way that we say an object is an instance of a class)
![Page 22: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/22.jpg)
Associations vs. Generalizations in Object Diagrams
Associations describe the relationships that will exist between instances at run time. • When you show an instance diagram generated
from a class diagram, there will be an instance of both classes joined by an association
Generalizations describe relationships between classes in class diagrams. • They do not appear in instance diagrams at all.
• An instance of any class should also be considered to be an instance of each of that class’s superclasses
![Page 23: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/23.jpg)
Aggregation
Aggregations are special associations that represent ‘part-whole’ relationships.
The ‘whole’ side is often called the assembly or the aggregate
This symbol is a shorthand notation association named isPartOf
![Page 24: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/24.jpg)
When to Use an Aggregation
As a general rule, you can mark an association as an aggregation if the following are true: You can state that
• the parts ‘are part of’ the aggregate
• or the aggregate ‘is composed of’ the parts
When something owns or controls the aggregate, then they also own or control the parts
![Page 25: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/25.jpg)
Composition
A composition is a strong kind of aggregation If the aggregate is destroyed, then the parts are
destroyed as well
Two alternatives for addresses
![Page 26: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/26.jpg)
Aggregation Hierarchy
![Page 27: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/27.jpg)
Propagation
A mechanism where an operation in an aggregate is implemented by having the aggregate perform that operation on its parts
At the same time, properties of the parts are often propagated back to the aggregate
Propagation is to aggregation as inheritance is to generalization. • The major difference is:
inheritance is an implicit mechanism propagation has to be programmed when required
![Page 28: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/28.jpg)
Interfaces
An interface describes a portion of the visible behavior of a set of objects.
An interface is similar to a class, except it lacks instance variables and implemented methods
![Page 29: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/29.jpg)
Notes and Descriptive Text
Descriptive text and other diagrams• Embed your diagrams in a larger document
• Text can explain aspects of the system using any notation you like
• Highlight and expand on important features, and give rationale
Notes: • A note is a small block of text embedded in a UML
diagram
• It acts like a comment in a programming language
![Page 30: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/30.jpg)
How do we model complex systems?Epistemology
Knowledge about Causality
(Dynamic Model)
Describes our knowledge about the system
Knowledge about Functionality(Functional model)
Knowledge about Relationships(Object model)
Neural Networks
DataFlow Diagrams (SA/SD)
Scenarios/Use Cases(Jacobsen)
Formal Specifications
(Liskov)
Petri Nets(Petri)Inheritance
Frames,SemanticNetworks (Minsky)
Uncertain KnowledgeFuzzy Sets (Zadeh)
Data Relationship(E/R Modeling, Chen)
Hierarchical Database
Model (IMS)
NetworkDatabase
Model(CODASYL)
RelationalDatabase Model
(Codd)
Fuzzy Frames(Graham)
Class Diagrams(“E/R + Inheritance”,
Rumbaugh)
Sequence Diagrams(Lamport)Activity
Diagrams(“good old Flowcharts”)
From (Bruegge & Dutoit, 2004)
![Page 31: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/31.jpg)
UML Interaction Diagrams
Model the dynamic aspects of the system by showing relationships among objects and the messages they may dispatch
Capture the behavior of a single use case Show a number of example objects and the
messages that are passed between these objects within the use case
![Page 32: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/32.jpg)
UML Interaction Diagrams
Sequence Diagram Emphasizes the time ordering of messages Focuses on the chronological course of the
messages
Collaboration Diagram Emphasizes the organization of the objects
that participate in an interaction Focuses on the cooperation among objects
![Page 33: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/33.jpg)
UML Collaboration Diagram
Shows a set of interactions between selected objects in a specific, limited situation, focusing on the relations between the objects and their topology
The chronological course of communication with each other is marked by numbering the messages
Shows the chronological sequences of the messages, their names and responses, and their possible arguments
One collaboration diagram for each use case
![Page 34: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/34.jpg)
Link
Links between objects are like associations in the class model
Enables objects to send messages There should be an association in the class
model between the two link objects Links may be instances of associations that are
shown in the class diagram
![Page 35: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/35.jpg)
Message
Links may be labeled with the names of messages
A communication between two objects that conveys information with the expectation that action will ensue
An event sent from one object to another An operation being invoked on another object Creation or destruction of an object instance
![Page 36: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/36.jpg)
Collaboration Diagram
Show objects and links
Superimpose messages on links
a : Assembly
part : CatalogEntry
1.1: number = getNumber(): Client
1 : count(part)
![Page 37: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/37.jpg)
Collaboration Diagram
: Registrar
course_form : CourseForm
theManager : CurriculumManageraCourse : Course
4 : <<create>>
3 : add_course()
1 : set_course_info()2 : process_form()
![Page 38: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/38.jpg)
Message Sequence
Sequence of messages are determined by numbering
Defines the order in which the interaction takes place 1, 2, 3, 4, ….. 1, 1.1, 1.2, 1.3, 2, 2.1, 2.1.1, 2.2, 3
(shows which operation calls which other operation)
![Page 39: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/39.jpg)
Sequence Diagram
Used to show the same interaction in a collaboration diagram but emphasize the order of the messages over time• Object instances are arranged horizontally
across the page
• Time runs vertically down the page
• Messages flow from left to right or from right to left
![Page 40: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/40.jpg)
Sequence Diagram
Time
Objects and Message Flows
![Page 41: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/41.jpg)
Lifeline
Objects are displayed at the top of the diagramThe vertical dimension represents timeEach object has a dashed line – lifeline – extending below it – to indicate the period of time during which objects playing that role actually exist
Object Name
![Page 42: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/42.jpg)
Message
The messages in an interaction are drawn from top to bottom, in the order that they are sent.
Messages are shown as arrows pointing from the lifeline of the role sending the message to the lifeline of the receiver.
When a message is sent, control passes from the sender of the message to the receiver.
Object Name Object Name
message
![Page 43: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/43.jpg)
Return
Return of control is shown using dashed arrow returning to the calling object.
Object Name Object Name
message
![Page 44: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/44.jpg)
Activation
• Period of time during which an object is processing a message
• Shown on a lifeline as a narrow rectangle whose top is connected to a message
• When an object finishes processing a message, control returns to the sender of the message
![Page 45: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/45.jpg)
Sequence Diagram
a : Assembly
part : CatalogEntry
getNumber()
: Client
count(part)
return number
Lifeline
Activation(optional)
Messages
control returns to the sender of the message (optional)
![Page 46: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/46.jpg)
Hierarchical Numbering of Messages
1.11
1.2
22.1
2.22.2.1
2.1.1
2.1.2
![Page 47: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/47.jpg)
Object Creation
course_form :CourseForm
theManager :CurriculumManager
aCourse :Course
: Registrar
set_course_info
process_formadd_course
<<create>>
Objectcreation
![Page 48: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/48.jpg)
Object Creation: Order Entry Example
Order OrderLinequantity: integer
cost: float
CatalogEntry
1 * 1*
: Client: Order :
CatalogEntry
OrderLine(qty,part)add(qty,part)
: OrderLinegetCost()
return cost
Objectcreation
![Page 49: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/49.jpg)
Object Destruction: Order Entry Example
: Client: Order
<<destroy>>remove(line)
: OrderLine
Objectdeletion
X
![Page 50: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/50.jpg)
Recurrence
When a sequence of messages takes place within an iteration, messages are grouped together within a rectangle
Object Name Object Name Object Name
message
message
*[recurrence condition]
![Page 51: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/51.jpg)
Branching
• Shown by 2 arrows branching off from the same point• Condition-clause is added to the message to show the condition
Object Name Object Name Object Name
[condition]message
[condition]message
![Page 52: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/52.jpg)
Conditional Message
• Messages which are sent only under certain circumstances• Not used in most cases because of the complexity of the resulting diagrams• Consists of a Boolean expression written in square brackets
![Page 53: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/53.jpg)
Conditional Message: Sequence Diagram
: Client: Order :
CatalogEntry
[s>=qty] OrderLine(qty,part)
add(qty,part)
: OrderLine
getCost()
return cost
getStockLevel(part)
return s
![Page 54: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/54.jpg)
Conditional Message: Communication Diagram
: Order : OrderLine
{new}
: CatalogEntry
1: add(qty, part)
1.2: [s>=qty] OrderLine(qty, part)
1.2.1: cost = getCost()
{new}
: Client
{new}
1.1: s =
getStockLevel(part)
![Page 55: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/55.jpg)
Message to Self
• A message that an object sends to itself gives rise to a new activation
• The new activation takes place in an object that already has a live activation
• The recursive nature of this new activation is shown by superimposing the new activation on top of the original one
![Page 56: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/56.jpg)
Self-Delegation: Sequence Diagram
: Client: Order : Customer
getShippingCost()
getTotal()
: OrderLine *
getLocation()
*getValue()
![Page 57: 08 class and sequence diagrams](https://reader034.vdocuments.site/reader034/viewer/2022051412/5490b023b479594c388b459f/html5/thumbnails/57.jpg)
Self-Delegation: Collaboration Diagram
: Order : Customer
: OrderLine *
1: getTotal()
1.2.1: getLocation()
: Client1.1*: g
etValue()
1.2: getShippingCost()
<<self>>