UML Class Diagrams Sequence Diagrams - PowerPoint PPT Presentation

1 / 45
About This Presentation
Title:

UML Class Diagrams Sequence Diagrams

Description:

Basic Modeling. Intermediate Modeling. Sequence Diagrams. Symbology. Class Diagrams ... Basic Class Diagrams. Superclass. Subclass. Inheritance (Generalization) ... – PowerPoint PPT presentation

Number of Views:275
Avg rating:3.0/5.0
Slides: 46
Provided by: CTO54
Category:
Tags: uml | class | diagrams | sequence

less

Transcript and Presenter's Notes

Title: UML Class Diagrams Sequence Diagrams


1
UML Class DiagramsSequence Diagrams
  • CSE230
  • Dae-Kyoo Kim

2
Agenda
  • Class Diagrams
  • Symbology
  • Basic Modeling
  • Intermediate Modeling
  • Sequence Diagrams
  • Symbology

3
Class Diagrams
  • A class diagram shows
  • Classes
  • Attributes
  • Methods
  • Interfaces
  • Collaborations
  • Relationships Dependency, Generalization,
    Association
  • A class diagram is a STATIC view of system

4
Basic Class Diagrams
Window
Class Name
size Sizevisibility boolean
Attributes
display()hide()
Operations
5
Basic Class Diagrams
public protected - private / derived
static
Abstract ltltabstractgtgt
ltltconstructorgtgt ltltquerygtgt ltltupdategtgt
Class Scope Variable
Visibility Attribute Name MultiplicityType
Initial Value Visibility Method Name (Parameter
List) Return-List
6
Attribute Example (Java implementation)
public class Note public String author
unknown public String text private static
long total 0 ...
7
Operation Example (Java implementation)
public class Figure private Size size
private Position pos private static long
figureCount 0 public void move(Position
pos) ... public static long
getFigureCount() return figureCount ...
8
Basic Class Diagrams
Superclass
Class with parts
Class with parts
Class A
Interface
name
Subclass
Assembly Class
Assembly Class
Class B
Concrete Class
Inheritance (Generalization) (is-a, kind-of)
Aggregation (Part-Of)
Association (relationship)
Dependency
Realization
9
Associations
  • A semantic relationship between two or more
    classes that specifies connections among their
    instances
  • A structural relationship specifying that objects
    of one class are connected to objects of a second
    (possibly the same) class
  • Example An Employee works for a Company

10
Associations (cont.)
  • 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

3
1
Book
currBorr
bk
11
Association(Java implementation)
  • public class Borrower
  • Book bk
  • int numBooks
  • public Borrower()
  • numBooks 0
  • bk new Book3
  • // methods that update bk
  • public void borrowBook( Book b )
  • bknumBooks b
  • numBooks
  • b.setBorrower( this )
  • public class Book
  • Borrower currBorr
  • public void setBorrower( Borrower bw )
  • currBorr bw

12
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.

4
Wheel
wheels
Whole
Part
13
Aggregation(Java implementation)
  • public class Car
  • private Wheel wheels
  • ...
  • // wheel objects are created externally and
  • // passed to the constructor
  • public Car( Wheel w1, Wheel w2, )
  • // we can check w1, w2, etc. for null
  • // to make sure wheels exist
  • wheels new Wheel4
  • wheels0 w1
  • wheels1 w2

14
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 one
  • The life time of the part is dependent upon the
    whole
  • The composite must manage the creation and
    destruction of its parts

15
Composition(C implementations)
  • class Circle public Circle() center(1,2)
    private Point center
  • class Circle public Circle() center(new
    Point(1,2)) Circle() delete center
    private Point const center

16
Composition(Java implementations)
  • public class Car
  • private Wheel wheels
  • ...
  • public Car()
  • wheels new Wheel4
  • // Wheels are created in Car
  • wheels0 new Wheel()
  • wheels1 new Wheel()
  • ...

17
Generalization
  • Indicates that objects of the specialized class
    (subclass) are substitutable for objects of the
    generalized class (super-class)
  • is kind of relationship

Shape
Super Class
An abstract class
Generalization relationship
Sub Class
Circle
18
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

19
Generalization(Java implementation)
  • public abstract class Shape public abstract
    void draw() ...
  • public class Circle extends Shape public
    void draw() ... ...

20
Dependency
  • A dependency indicates a semantic relation
    between two or more classes in which a change in
    one may force changes in the other although there
    is no explicit association between them
  • A stereotype may be used to denote the type of
    the dependency

21
Dependency(Java implementation)
  • public class Bank
  • public void processTransactions()
  • // Parser p is a local variable
  • Parser p new Parser()
  • p.getTransaction()

22
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
ltltinterfacegtgtList
LinkedList
List
23
Realization(Java implementation)
  • public interface List boolean add(Object o)
    ...
  • public class LinkedList implements List
    public boolean add(Object o)
  • ...
  • ...

24
Basic Class Diagram (Example)
takes
25
Basic Class Diagram (Example)
Person
name String - ssn String birthday
Date / age int
getName String -calculateAge int
26
Class Diagrams (Advanced)
Cardinality (Multiplicity) 1 0..1 0..n 1..n

takes
0..n
27
Class Diagrams (Advanced)
Important Stereotypes ltltinterfacegtgt specify
collection of operations to specify
services ltlttypegtgt specify structure and
behavior (not implementation) ltltenumerationgtgt
specify discrete values ltltimplementationClassgtgt
helper class created in detail design
ltltenumerationgtgt Status
Idle Working Error
Fundamental Attributes
readImage writeImage
Fundamental behavior
28
Class Diagrams (Advanced)
Simple Aggregation (object lifetime)
Composite Aggregation (unique member)
Can have self-relations
Exception handling
ltltsendsgtgt
manager
manages
employee
29
Class Diagrams (Advanced)
Association Class
30
TVRS Example
TrafficReport
Offender
issues
1

TrafficPoliceman
1..
1
id long
name String
description String
id long
occuredAt Date
reports of
1..
Policeman
Violation
id long
name String
id long
rank int
description String
ltltabstractgtgt
31
Class Diagrams (Advanced)
32
Class Diagram Hints
  • Provide abstraction of problem domain
  • Embodies small set of well-defined
    responsibilities
  • Clear separation between specification and
    implementation
  • Understandable and simple
  • Show only important properties

33
Class Hints
  • Organize similar classes into packages
  • Beware of cyclical generalization
  • Use associations where there are structural
    relationships
  • Associations are NOT comm pipes!!!!!!!
  • Start with Analysis, then refine details

34
Sequence Diagrams
  • AKA Interaction Diagrams Semantically
    equivalent to Collaboration Diagrams
  • Dynamic Model relating use cases and class
    diagrams
  • Illustrates how objects interacts with each other
  • Shows time ordering of interactions
  • Generally a set of messages between collaborating
    objects
  • Ordering of objects not significant

35
Sequence Diagrams
  • Show only one flow of control
  • Can model simple sequential flow, branching,
    iteration, recursion and concurrency
  • May need multiple diagrams
  • Primary
  • Variant
  • Exceptions

36
Sequence Diagram (Basic)
Object Class or Actor
name
Focus of Control/ Activation
message
Object Destruction/ Termination
X
ltltcreategtgt ltltdestroygtgt
37
Sequence Diagram (Basic)
aClass Class
Register
adjustRoom
checkRooms
38
Sequence Diagram (Basic)
X-Axis (objects)
memberLibraryMember
Object
Life Line
Y-Axis (time)
message
Activation box
condition
39
Sequence Diagrams (Advanced)
Seq Guard Iteration Return-List
Operation-Name (Argument-List)
Conditional Lifeline
transient
40
Object
  • Object naming
  • syntax instanceNameclassName
  • Name classes consistently with your class diagram
    (same classes).
  • Include instance names when objects are referred
    to in messages or when several objects of the
    same type exist in the diagram.
  • The Life-Line represents the objects life during
    the interaction

41
Messages
  • An interaction between two objects is performed
    as a message sent from one object to another
    (simple operation call, Signaling, RPC)
  • If object obj1 sends a message to another object
    obj2 some link must exist between those two
    objects (dependency, same objects)

42
Messages (Cont.)
  • A message is represented by an arrow between the
    life lines of two objects
  • Self calls are also allowed
  • The time required by the receiver object to
    process the message is denoted by an
    activation-box
  • A message is labeled at minimum with the message
    name
  • Arguments and control information (conditions,
    iteration) may be included

43
Return Values
  • Optionally indicated using a dashed arrow with a
    label indicating the return value.
  • Dont model a return value when it is obvious
    what is being returned, e.g. getTotal()
  • Model a return value only when you need to refer
    to it elsewhere, e.g. as a parameter passed in
    another message.
  • Prefer modeling return values as part of a method
    invocation, e.g. ok isValid()

44
Sequence Diagram (Basic)
Clerk
lookup
viewButton()
idgetID()
getViolation(id)
May be a pseudo-method
ltltcreategtgt
v
display(v)
45
Sequence Diagram (Basic)
Active object
Client
print(doc,client)
enqueue(job)
Repeated forever with 1 min interludes
jobprint(job.doc)
status
job done(status)
Write a Comment
User Comments (0)
About PowerShow.com