uml part ii - politechnika częstochowskadyja/pliki/se/lecture04.pdf · · 2016-11-08i...
TRANSCRIPT
UML – part II
UML – part II 1/41
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
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
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
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
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
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
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
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
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
Dependency relationship
UserInterface BlogEntry
The Dependency Arrow
Figure: Dependency relationship
UML – part II 11/41
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
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
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
Generalization
Article
WikiPage
The more generalized
classes
BlogEntry
The Generalization
Arrow
The more specialized classes
Figure: Generalization relationship (Inheritance)
UML – part II 15/41
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
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
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
Class template
Figure: A template with a concrete class
UML – part II 19/41
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
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
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
Object diagram
Properties:
I Object diagram is a part of logical viewI Object diagram shows object instances
UML – part II 23/41
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
Object diagram
Figure: An example of object diagram
UML – part II 25/41
Object diagram
Figure: Object diagram for an association class
UML – part II 26/41
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
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
Properties
Figure: Class diagram
Figure: Internal Structure diagram
UML – part II 29/41
Class instances
Figure: An instance of Frame
UML – part II 30/41
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
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
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
Component diagram
UML – part II 34/41
Packages
A B
C D
Figure: Example of a system with four packages (A, B, C, D)
UML – part II 35/41
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
Package Dependency
gui util
accounts users security
search
indexing
Figure: A package depends on another package
UML – part II 37/41
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
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
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
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