Top Banner
CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram
32

CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Jan 19, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

CS212: Object Oriented Analysis and Design

Lecture 33: Class and Sequence Diagram

Page 2: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Recap of Lecture 32

• Introduction to Modeling

• Identifying use case

• Role

• Use case diagram

Page 3: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Outline of Lecture 33

• Class diagram

• Sequence Diagram

Page 4: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Class Diagram

• Use the class diagram to model the static structure of a system

• Describes the elements of the system and the relationships between them

• Class diagram allows to create a conceptual view of the system and to define the vocabulary to be used

Page 5: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Essential features

• Class

• Attributes

• Operations

• Relationships• Associations• Generalization• Realization

• Dependency

• Constraint Rules and Notes

Page 6: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Class

• Describes a set of objects having similar:• Attributes (status)• Operations (behavior)• Relationships with other classes

• Attributes and operations may• have their visibility marked:• "+" for public• "#" for protected• "−" for private• "~" for package

Page 7: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Example

Class Name

Attributes

Operations

Page 8: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Associations

• An association between two classes indicates that objects at one end of an association “recognize” objects at the other end and may send messages to them.

• Example: “An Employee works for a Company”

Employee Company

Page 9: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Associations (cont.)

• To clarify its meaning, an association may be named.• The name is represented as a label placed midway along the

association line.

• Usually a verb or a verb phrase.

• A role is an end of an association where it connects to a class.• May be named to indicate the role played by the class

attached to the end of the association path.

• Usually a noun or noun phrase• Mandatory for reflexive associations

Page 10: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Associations (cont.)

• Multiplicity• the number of objects that participate in the association.• Indicates whether or not an association is mandatory.

Exactly one 1

Zero or more (unlimited) * (0..*)

One or more 1..*

Zero or one (optional association) 0..1

Specified range 2..4

Multiple, disjoint ranges 2, 4..6, 8

Multiplicity Indicators

Page 11: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Associations: Example

StaffMember Student1..* *instructs

instructor

Association name

Role name

MultiplicityNavigable

(uni-directional) association

Courses

pre - requisites

0..3Reflexive

association

Role

*

Page 12: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Aggregation

• A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts.

• Models a “is a part-part of” relationship.

Whole Part

Car Door House1..*2..*

Page 13: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Aggregation (cont.)

• Aggregation tests:• Is the phrase “part of” used to describe the relationship?

• A door is “part of” a car

• Are some operations on the whole automatically applied to its parts?

• Move the car, move the door.

• Are some attribute values propagated from the whole to all or some of its parts?

• The car is blue, therefore the door is blue.

• Is there an intrinsic asymmetry to the relationship where one class is subordinate to the other?

• A door is part of a car. A car is not part of a door.

Page 14: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Composition

• A strong form of aggregation• The whole is the sole owner of its part.

• The part object may belong to only one whole

• Multiplicity on the whole side must be zero or one.

• The life time of the part is dependent upon the whole. • The composite must manage the creation and

destruction of its parts.

Circle Point

3..*

1

PolygonPoint

Circle

Page 15: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Generalization• Indicates that objects of the specialized class (subclass) are

substitutable for objects of the generalized class (super-class).

• “is kind of” relationship.

Shape{abstract}

Circle

Super Class

Sub Class

An abstract class

Generalization relationship

{abstract} is a tagged value that indicates that the class is abstract. The name of an abstract class should be italicized

Page 16: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Generalization

• A sub-class inherits from its super-class• Attributes• Operations• Relationships

• A sub-class may• Add attributes and operations• Add relationships• Refine (override) inherited operations

• A generalization relationship may not be used to model interface implementation.

Page 17: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Realization

• A realization relationship indicates that one class implements a behavior specified by another class (an interface or protocol).

• An interface can be realized by many classes.

• A class may realize many interfaces.

LinkedList<<interface>>

List ArrayList

Page 18: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Dependency

• Dependency is a weaker form of relationship which indicates that one class depends on another because it uses it at some point in time.

• One class depends on another if the independent class is a parameter variable or local variable of a method of the dependent class.

• This is different from an association, where an attribute of the dependent class is an instance of the independent class.

Iterator Vector<<friend>>

Page 19: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Constraint Rules and Notes

• Constraints and notes annotate among other things associations, attributes, operations and classes.

• Constraints are semantic restrictions noted as Boolean expressions.

• UML offers many pre-defined constraints.

id: long { value > 0 }

CustomerOrder*1

{ total < $50 }may be canceled

Constraint Note

Page 20: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

The Sequence Diagram

• The interactions between the objects in a system

• An interaction specifies how messages and data are exchanged between interaction partners.

• Interaction partners: human, non-human, server, printers, etc..

• The sequence diagram is a two-dimensional diagram

Page 21: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Importance

• Depict object interactions in a given scenario identified for a given Use Case

• Specify the messages passed between objects using horizontal arrows including messages to/from external actors

• Time increases from Top to bottom

Page 22: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Rules of Sequence Diagrams

• Sequence Initiation

updateStatus( )

Click Update Button

User

Object1:C1 Object2:C2

Page 23: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Rules of Sequence Diagrams

• Identify objects needed to support use case, determine sequence of internal events following the external initiating event

• Diagrams that are not initiated with an external actor represent only a partial sequence

• Partial sequence diagrams should clearly identify the actor initiated sequence diagrams from which they are launched

Page 24: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Structure of a sequencediagram

Page 25: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Rules of Sequence Diagrams

• Messages specified on interactions can be synchronous or asynchronous

updateStatus( )

Object1:C1 Object2:C2

calcRoute( )

route

Object1:C1 Object2:C2

Implicit Returns Explicit Return

Object3:C3

generateMessage( )

Synchronous call

Page 26: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Rules of Sequence Diagrams

Asynchronous call

asynchronous_Call ()

callBack ()

Object1:C1{active}

Object2:C2{active}

Page 27: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Rules of Sequence Diagrams

• Display operation names on call arrows

c:clientfactory:

cmd_pktCToCHeaderFactory

header:cmd_pktCToCCommandHeaderbuildHeader( char * )

«create»

header

Page 28: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Specifying Timing Requirements

a: Command

Create Transaction

b: Command

d: ResponseRemove Transaction

c: Response

CMM : process target : process

User Application

{b.receiveTime a.sendTime + 50ms}

{d.receiveTime a.sendTime + 1s}

Page 29: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Example: Use Case Diagram of the Vending Machine

C u s to m e r

D ep o s it M o n ey

M ak e S e lec tio n

M a in te n a n ceO pe ra to r

Up d ate D atab as e

C an c ella tio n

Page 30: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

The Initial Object-Model

V e n din g M a ch in eC o n tro lle r

Nu m e ric K e y pa d

W ire le s sK e y bo a rd

C R T D is pla y

M o n e y D e te ct io nH a rdwa re

M o n e y D is pe n s e r

Pro du ctD is pe n s e r

Pro du ct D a ta ba s e

Designate the Actor objects with the <<actor>> stereotype above the object label

<<actor>>

<<actor>>

<<actor>>

<<actor>>

<<actor>>

<<actor>>

Page 31: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Deposit Money Use Case

C u s to m e r

M o n e y D e te c t io nH a rd w a re

CRT D is p la yVe n d in g M a c h in e

Co n t ro lle r

D e p o s it M o n e y

[Id le S ta te ]D is p la y W e lc o meM e s s a g e

D is p la y A mo u n t

S e n d A mo u n t

P ro mp t fo r S e le c t io n

S ta rt T ime r

[If T ime r > 30 s e c o n d s a n d In v a lid o r N o S e le c t io n ] Re tu rn M o n e y

M o n e yD is p e n s e r

S to pT ime r[Id le S ta te ]

D is p la y W e lc o meM e s s a g e

Page 32: CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.

Thank youNext Lecture: UML Diagrams