uml part ii - politechnika częstochowskadyja/pliki/se/lecture04.pdf ·  · 2016-11-08i...

41
UML – part II UML – part II 1/41

Upload: votuyen

Post on 02-May-2018

219 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

UML – part II

UML – part II 1/41

Page 2: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Class

The most important facts about classes:I the difference between a class and its instance (object)

I objects are created on a basis of classes (they are classinstances)

I class instance stateI object stores its state by using attributes (data)

I class behaviorI class behavior describes operations that class can do (messages

that can be sent to class)I class should only include necessary informations (abstraction)

UML – part II 2/41

Page 3: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Encapsulation

I in object-oriented approach the object contains attributes andoperations

I encapsulation enables a class to hide the inner details of howit works

I with encapsulation small changes to how classes workinternally shouldn’t break a system

UML – part II 3/41

Page 4: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

A class in UML notation

ClassName

+attribute1

+attribute2

+operation_a()

+operation_b()

ClassName

+attribute1

+attribute2

ClassName

+operation_a()

+operation_b()

ClassName

Figure: Different ways of showing a class using UML notation

UML – part II 4/41

Page 5: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Visibility

More accessible to other

parts of the system

Less accessible to

other parts of the system

Name

(Notation)

Public

(+)

Protected

(#)

Package

(~)

Private

(-)

Figure: UML’s different visibility classifications

UML – part II 5/41

Page 6: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Attributes

BlogAccount

-name: String

+publicURL: URL

BlogEntry-entries

Inline

attributes

Visibility

Name Type

An attribute

by association

Figure: Representation of attributes in UML notation

UML – part II 6/41

Page 7: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Multiplicity

BlogAccount

-name: String

+publicURL: URL

-authors:Author[1..5]{unique}

BlogEntry

-trackbacks: Trackback[*]{unique}

-comments: Comment[*]{ordered}-entries {ordered}

1 *

Figure: Different flavors of attribute multiplicity

UML – part II 7/41

Page 8: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Operations

BlogAccount

-name: String

+publicURL: URL

-authors:Author[1..5]{unique}

+addEntry(newEntry:BlogEntry): void

+BlogAccount(name:String)

Visibility

NameParentheses for

Parameters

Return Type

An operation

Figure: Class operation

UML – part II 8/41

Page 9: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Static parts of classes

BlogAccount

-name: String

+publicURL: URL

-accountCounter: int

-authors:Author[1..5]{unique}

+addEntry(newEntry:BlogEntry): void

+BlogAccount(name:String)

Figure: The static part of a class is marked by highlighting

UML – part II 9/41

Page 10: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Class Relationships

Different types of class relationship from the weakest to thestrongest

I dependency – when objects of one class work briefly witrhobjects of another class

I association – when objects of one class work with objects ofanother class for some prolonged amount of time

I aggregation – when one class owns but shares a reference toobjects of another class

I composition – when one class contains objects of another classI inheritance – when one class is a type of another class

UML – part II 10/41

Page 11: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Dependency relationship

UserInterface BlogEntry

The Dependency Arrow

Figure: Dependency relationship

UML – part II 11/41

Page 12: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Association

Example:

c l a s s A {p r i v a t e :B∗ b ;

} ;c l a s s B {

} ;

UML – part II 12/41

Page 13: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Aggregation

A B

Aggregation Arrow

1 *

-b

Figure: Aggregation relationship

Example:

c l a s s A {p r i v a t e :s t d : : v e c to r<B∗> b ;

} ;c l a s s B {} ;

UML – part II 13/41

Page 14: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Composition

A B

Composition Diamond

11

-b

Figure: Composition relationship

Example:

c l a s s A {p u b l i c :v i r t u a l ˜A( ) { d e l e t e b ;}p r i v a t e :B∗ b ;

} ;c l a s s B {} ;

UML – part II 14/41

Page 15: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Generalization

Article

WikiPage

The more generalized

classes

BlogEntry

The Generalization

Arrow

The more specialized classes

Figure: Generalization relationship (Inheritance)

UML – part II 15/41

Page 16: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Association class

Figure: A BlogEntry is associated with a Category by the fact that it isassociated with a particular BlogAccount

UML – part II 16/41

Page 17: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Abstract class

Store

+store(articles:Article[]): void

+retrieve(): Article[]

Abstract

operations in

italics

Concrete

operations in

regular font

BlogStore

+store(articles:Article[]): void

+retrieve(): Article[]

Figure: Abstract class

UML – part II 17/41

Page 18: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Interface implementation

<<interface>>

EmailSystem

+send(message:Message): void

EmailSystem

+ send(message:Message):void

SMTPMailSystem

+send(message:Message): void

SMTPMailSystem

+send(message:Message): void

Figure: Interface implementation (realization)

UML – part II 18/41

Page 19: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Class template

Figure: A template with a concrete class

UML – part II 19/41

Page 20: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Constraints

BlogEntry

-url: URL

-rating: int

{rating>=0}

+updateRating(newRating:int): void

self.url->notEmpty()

context BlogEntry::updateRating(newRating:int):void

pre:rating>=0

post:rating<=5

Types of constraints

I InvariantsI PreconditionsI Postconditions

UML – part II 20/41

Page 21: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

OCL

OCL expressions

I baseCost >= 0.0I totalCost = baseCost ∗ (1 + getTaxRate())I status <> ′Unpaid′

OCL types

I BooleanI IntegerI RealI String

UML – part II 21/41

Page 22: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

OCL

OCL operators

I Arithmetic ∗, /, +, −I Additional Arithmetic max(), min(), avg(), abs()I Comparison <=, <, >=, >

I Equality =, <>

I Boolean and , or , xor , notI String concat(), size(), substring()

UML – part II 22/41

Page 23: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Object diagram

Properties:

I Object diagram is a part of logical viewI Object diagram shows object instances

UML – part II 23/41

Page 24: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Object instance

entry:BlogEntry

ui:UserInterface

Figure: Object instances and links between them

I If you create a link between two objects, there must be acorresponding association between the classes

I You can use anonymous objects, which are useful when thename of the object is not important within the context that itis being used

UML – part II 24/41

Page 25: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Object diagram

Figure: An example of object diagram

UML – part II 25/41

Page 26: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Object diagram

Figure: Object diagram for an association class

UML – part II 26/41

Page 27: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Internal structure diagramBlogEntry

Introduction MainBody

blogIntro

1

blogMain

1

Figure: Class diagram

BlogEntry

1

blogIntro:Introduction

1

blogMain:MainBody

"Owning class"

Multiplicity

Parts

Role Class

Figure: Internal structure diagram

UML – part II 27/41

Page 28: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

ConnectorsBlogEntry

1

blogIntro:Introduction

1

blogMain:MainBody

Connector

11

Figure: Using connectors to link parts in the internal structure of a class

I A connector is a link that enables communication betweenparts

I The notation for multiplicities on connectors is the same asmultiplicities on associations

UML – part II 28/41

Page 29: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Properties

Figure: Class diagram

Figure: Internal Structure diagram

UML – part II 29/41

Page 30: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Class instances

Figure: An instance of Frame

UML – part II 30/41

Page 31: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Ports

Wiki

Updateable

Viewable

VersionControl

Rollback

UserServices Maintenance

Figure: A class with two ports showing that the class provides twodifferent capabilities

I A port is a point of interaction between a class and theoutside world (Interface)

I You can use ports to group related interfaces to show theservices available at that port

UML – part II 31/41

Page 32: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Component diagram

Component

I A component is an encapsulated, reusable, and replaceablepart of your software

I In UML, a component can do the same things a class can doI UML component diagrams model the components in your

system and as such form part of the development view

UML – part II 32/41

Page 33: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Component diagram

I A provided interface of a component is an interface that thecomponent realizes

I A required interface of a component is an interface that thecomponent needs to function

I You can use ports to model distinct ways that a componentcan be used with related interfaces attached to the port

UML – part II 33/41

Page 34: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Component diagram

UML – part II 34/41

Page 35: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Packages

A B

C D

Figure: Example of a system with four packages (A, B, C, D)

UML – part II 35/41

Page 36: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Contents of a Packagesearch

indexing

security

Credentials

IdentityVerifier

Figure: A way of showing the content of a package

security::Credentials

security::IdentityVerifier

search::indexing

Figure: Providing a scope of package content

UML – part II 36/41

Page 37: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Package Dependency

gui util

accounts users security

search

indexing

Figure: A package depends on another package

UML – part II 37/41

Page 38: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Importing and Accessing Packages

A

C

B

D

<<import>>

<<import>>

<<access>>

Figure: Package A can see public elements in C but not D

UML – part II 38/41

Page 39: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Importing and Accessing Packages

security

users<<import>> +Credentials +IdentityVerifier

-MD5Crypt

users

<<import>>

security

Figure: The package users imports security

security

users

<<import>> +Credentials +IdentityVerifier

-MD5Crypt

Figure: The users package imports only one class from the securitypackage

UML – part II 39/41

Page 40: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Using Packages to Organize Use Cases

Administrator

Author

Public

Account Management

Authoring

Search

Figure: Packages enable a higher level view of how actors interact withthe system

UML – part II 40/41

Page 41: UML part II - Politechnika Częstochowskadyja/pliki/SE/lecture04.pdf ·  · 2016-11-08I association – when objects of ... I aggregation – when one class owns but shares a reference

Bibliography

I Miles R., Hamilton K.: Learning UML 2.0, Helion, Gliwice2007,

I UML 2.1 Tutorial,http://www.sparxsystems.com.au/resources/uml2 tutorial/

UML – part II 41/41