60
2IW80 Software specification and architecture Structural specification: beyond class diagrams Alexander Serebrenik

UML package diagrams

Embed Size (px)

Citation preview

Page 1: UML package diagrams

2IW80 Software specification and architecture

Structural specification:

beyond class diagrams

Alexander Serebrenik

Page 2: UML package diagrams

Before we start

/ SET / W&I PAGE 1 24-2-2014

• Match the pairs

1 Association A

2 Aggregation B

3 Composition C

4 Implementation D

5 Generalization E

6 Dependency F

Page 3: UML package diagrams

Before we start

/ SET / W&I PAGE 2 24-2-2014

• Match the pairs

1 Association A

2 Aggregation B

3 Composition C

4 Implementation D

5 Generalization E

6 Dependency F

1E 2C 3F 4A 5D 6B

Page 4: UML package diagrams

Before we start

/ SET / W&I PAGE 3 24-2-2014

• A patient must be assigned to only one doctor, and a

doctor can have one or more patients.

Patient x y

Doctor

Determine x and y

Page 5: UML package diagrams

This week sources

Slides by

David Meredith,

Aalborg University, DK

Marie-Elise Kontro,

Tampere University, FI

Site by

Kirill Fakhroutdinov

GE Healthcare, USA

Page 6: UML package diagrams

Recall

Structural diagram is a diagram that identifies modules,

activities, or other entities in a system or computer program

and shows how larger or more general entities break down

into smaller, more specific entities.

IEEE Standard Glossary of Software Engineering

Terminology 610.12 1990

/ SET / W&I PAGE 5 24-2-2014

Page 7: UML package diagrams

UML structure diagrams

/ SET / W&I PAGE 6 24-2-2014

Class diagram

Composite structure diagram

Packages diagram

Component diagram

Object diagram

Deployment diagram

Page 8: UML package diagrams

Between specification and architecture

• Packages diagram and deployment diagram: the

closest UML diagrams come to architecture

• more about architecture: second half of the quartile

/ SET / W&I PAGE 7 24-2-2014

Page 9: UML package diagrams

Packages diagram

• Represents the system at a higher abstraction level

• Android SDK – 69 packages vs. 1231 classes

• less prone to change, ergo better suited for evolution, than

lower level representations

• NB: Packages diagram (UML standard) is frequently

called package diagram

/ SET / W&I PAGE 8 24-2-2014

Page 10: UML package diagrams

Packages diagram: Packages and Relations

• Packages

• groups of “basic elements”, e.g., classes or use cases

• namespaces, i.e., all members should have unique names

• represented as file folders

• can contain other packages, creating hierarchy

• Relations

• dependencies, implementations, …

• imports and merges

/ SET / W&I PAGE 9 24-2-2014

Page 11: UML package diagrams

Package representations

/ SET / W&I PAGE 10 24-2-2014

Types

Package Types,

members not shown

Types

Time

Date

Package Types, some members

within the borders of the package

Types

Shape Point

Package Types, some members

shown using -notation

Types

Temporal

Nested packages

Page 12: UML package diagrams

Relations

• Dependency

• Implementation

• Import / access

• Merge

/ SET / W&I PAGE 11 24-2-2014

Page 13: UML package diagrams

Relations: Dependencies

• Package A depends on package B if A contains a class

which depends on a class in B

• Summarise dependencies between classes

• Graphic representation:

or

<<use>>

Page 14: UML package diagrams

Relations: Dependencies

• Package A depends on package B if A contains a class

which depends on a class in B

• Summarise dependencies between classes

• Typical 3-tier application (sketch):

Presentation layer

Business layer

Data layer

UI, web-interface,

services to other

systems

Core calculations,

operations, etc

Data storage (DB)

Page 15: UML package diagrams

Relations: Dependencies

• Package A depends on package B if A contains a class

which depends on a class in B

• Summarise dependencies between classes

• Martin’s Acyclic Dependency Principle

there should be no cycles in the dependencies

• Fowler:

If there are cycles in dependencies, these cycles should be

localized, and, in particular, should not cross the tiers

Page 16: UML package diagrams

Relations: Implementations

• Meaningful if multiple variants are present

/ SET / W&I PAGE 15 24-2-2014

Database

Gateway

MySQL Gateway Oracle Gateway SQL Server

Gateway

Page 17: UML package diagrams

Relations: Import / access

• To understand the import / access relation between

packages

• We need to know how elements can reference each other

• What does an element import / access mean

• How this notion can be generalized to packages

/ SET / W&I PAGE 16 24-2-2014

Page 18: UML package diagrams

17

How elements can reference each other? (1)

• Element can refer to other elements that are in its

own package and in enclosing packages without

using fully qualified names

p

q

E s D

r

B C A foo

Page 19: UML package diagrams

Do you remember?

• Fully qualified name: a globally unique identifier of a

package, class, attribute, method.

• Fully qualified name is composed of

• qualifier: all names in the hierarchic sequence above the

given element

• the name of the given element itself

• Notation

• UML, C++, Perl, Ruby p::A::foo, p::r::C

• Java, C# p.A.foo, p.r.C

/ SET / W&I PAGE 18 24-2-2014

p

A foo

r

C

Page 20: UML package diagrams

19

How elements can reference each other? (2)

• Element can refer to other elements that are in its

own package and in enclosing packages without

using fully qualified names

p

q

E s D

r

B C A foo

Page 21: UML package diagrams

Element Import (1)

• Element import allows an element in another package to

be referenced using its name without a qualifier

• <<import>> imported element within importing package is public

• <<access>> imported element within importing package is private

/ SET / W&I PAGE 20 24-2-2014

Page 22: UML package diagrams

Element Import (2)

• Element import allows an element in another package to

be referenced using its name without a qualifier

• <<import>> imported element within importing package is public

• <<access>> imported element within importing package is private

/ SET / W&I PAGE 21 24-2-2014

h

e

a

C

F

b

F

C

D

<<import>>

Page 23: UML package diagrams

Element Import (3)

• Element import allows an element in another package to

be referenced using its name without a qualifier

• <<import>> imported element within importing package is public

• <<access>> imported element within importing package is private

/ SET / W&I PAGE 22 24-2-2014

h

e

a

C

F

b

F

C

D

<<import>> C

or

Page 24: UML package diagrams

Element Import (4)

• Element import allows an element in another package to

be referenced using its name without a qualifier

• <<import>> imported element within importing package is public

• <<access>> imported element within importing package is private

/ SET / W&I PAGE 23 24-2-2014

h

e

a

C

F

b

F

C

D

<<import>> C

should be

referred as e::C

in a

Page 25: UML package diagrams

Element Import (5)

• Element import allows an element in another package to

be referenced using its name without a qualifier

• <<import>> imported element within importing package is public

• <<access>> imported element within importing package is private

/ SET / W&I PAGE 24 24-2-2014

h

e

a

C

F

b

F

C

D

<<import>>

F cannot be imported to a since

there is already an F in a. Hence,

we need to rename b::F to G in a.

Page 26: UML package diagrams

Element Import (6)

• Element import allows an element in another package to

be referenced using its name without a qualifier

• <<import>> imported element within importing package is public

• <<access>> imported element within importing package is private

/ SET / W&I PAGE 25 24-2-2014

h

e

a

C

F

b

F

C

D

<<import>>

b::F is accessible as G in h, b::C is

accessible as C in h, b::D is not

accessible in h (private visibility of

b::D in a due to <<access>>).

Page 27: UML package diagrams

Package import (1)

• A package import identifies a package whose members

are to be imported

• Conceptually equivalent to having an element import to

each individual member of the imported package

• <<import>> if package import is public

• <<access>> if package import is private

/ SET / W&I PAGE 26 24-2-2014

Page 28: UML package diagrams

Package import (2)

• A package import is a directed relationship that

identifies a package whose members are to be imported

• Conceptually equivalent to having an element import to

each individual member of the imported package

• <<import>> if package import is public

• <<access>> if package import is private

/ SET / W&I PAGE 27 24-2-2014

auxiliary

shoppingCart

types

webShop <<import>>

Are elements of types accessible from webShop?

Are elements of auxiliary accessible from webShop?

Are elements of types accessible from shoppingCart?

Are elements of auxiliary accessible from shoppingCart?

Page 29: UML package diagrams

Package import (2)

• A package import is a directed relationship that

identifies a package whose members are to be imported

• Conceptually equivalent to having an element import to

each individual member of the imported package

• <<import>> if package import is public

• <<access>> if package import is private

/ SET / W&I PAGE 28 24-2-2014

auxiliary

shoppingCart

types

webShop <<import>>

Are elements of types accessible from webShop? YES

Are elements of auxiliary accessible from webShop? NO

Are elements of types accessible from shoppingCart? YES

Are elements of auxiliary accessible from shoppingCart? YES

Page 30: UML package diagrams

Relations: Recap

Dependency

Implementation

Import / access

• Merge

/ SET / W&I PAGE 29 24-2-2014

Page 31: UML package diagrams

Package merge

• A package merge indicates that the contents of the two

packages are to be combined.

• A (merged package) is merged into B (receiving package)

that becomes B’ (resulting package)

/ SET / W&I PAGE 30 24-2-2014

Page 32: UML package diagrams

Package merge

• A package merge indicates that the contents of the two

packages are to be combined.

• A (merged package) is merged into B (receiving package)

that becomes B’ (resulting package)

• Merge is possible only if

• There is no cycle on “merge” dependencies

• Receiving package does not contain the merged package

• Receiving package is not contained in the merged package

• Receiving element cannot have references to the merged

element

• Matching typed elements should have the same type (class)

or a common supertype (superclass)

/ SET / W&I PAGE 31 24-2-2014

Page 33: UML package diagrams

Merge rules

UML 2.5 Beta 2, pp. 252-262

http://www.omg.org/spec/UML/2.5/Beta2/

/ SET / W&I PAGE 32 24-2-2014

s

D

B A

q

C A <<merge>>

merged package receiving package

s

D

B A

C

resulting package

Merge of s::A

and q::A

Copied

from s

Copied

from s

Copied

from q

Page 34: UML package diagrams

Merge rules

UML 2.5 Beta 2, pp. 252-262

http://www.omg.org/spec/UML/2.5/Beta2/

/ SET / W&I PAGE 33 24-2-2014

s

A

B

q

B A <<merge>>

merged package

receiving

package

s

A

B

resulting

package

Merge of s::B

and q::B

Merge of s::A

and q::A

Page 35: UML package diagrams

Summary: UML package diagrams

/ SET / W&I PAGE 34 24-2-2014

http://www.uml-diagrams.org/package-diagrams-overview.html

Page 36: UML package diagrams

How do we organize classes/use-cases in

packages?

• General: try to give packages meaningful names

• Two special cases:

• Class package diagrams

− “basic elements” are class diagrams

− The most popular special case

• Use-case package diagrams

− “basic elements” are use-case diagrams

− Useful for larger projects to organize requirements

/ SET / W&I PAGE 35 24-2-2014

Page 37: UML package diagrams

Class Package Diagrams

• Heuristics to organize classes into packages:

• Classes of a framework belong in the same package.

• Classes in the same inheritance hierarchy typically belong

in the same package.

• Classes related to one another via aggregation or

composition often belong in the same package.

• Classes that collaborate with each other a lot often belong

in the same package.

/ SET / W&I PAGE 36 24-2-2014

Page 38: UML package diagrams

How would you organize into 2 packages?

• Car, Cylinder, Driver, Driving License, Engine, Person,

Wheel

/ SET / W&I PAGE 37 24-2-2014

Page 39: UML package diagrams

How would you organize into 2 packages?

• Car, Cylinder, Driver, Driving License, Engine, Person,

Wheel

/ SET / W&I PAGE 38 24-2-2014

Car

Wheel Engine

Cylinder

Person

Driver

Driving License 4 1

2,4,6,8,10,12

Page 40: UML package diagrams

How would you organize into 2 packages?

• Car, Cylinder, Driver, Driving License, Engine, Person,

Wheel

/ SET / W&I PAGE 39 24-2-2014

Car

Wheel Engine

Cylinder

Person

Driver

Driving License 4 1

2,4,6,8,10,12

Vehicle

Individual

Page 41: UML package diagrams

How would you organize into 2 packages?

• Car, Cylinder, Driver, Driving License, Engine, Person,

Wheel

/ SET / W&I PAGE 40 24-2-2014

Vehicle

Individual

Page 42: UML package diagrams

Use-Case Package Diagrams

• Heuristics to organize use cases into packages:

• Keep associated use cases together: included, extending

and inheriting use cases belong in the same package.

• Group use cases on the basis of the needs of the main

actors.

/ SET / W&I PAGE 41 24-2-2014

Page 43: UML package diagrams

Use-Case Package Diagram Example

/ SET / W&I PAGE 42 24-2-2014

http://www.students.tut.fi/~kontrom/files/Lecture6.pdf

Page 44: UML package diagrams

UML structure diagrams

/ SET / W&I PAGE 43 24-2-2014

Class diagram

Composite structure diagram

Packages diagram

Component diagram

Object diagram

Deployment diagram

Page 45: UML package diagrams

Component diagrams

• Component: a modular unit with well-defined interfaces

that is replaceable within its environment (UML Superstructure

Specification, v.2.0, Chapter 8)

• fosters reuse

• stresses interfaces

• Graphical representation: special kind of class

/ SET / W&I PAGE 44 24-2-2014

<<component>>

Account

Account

Account

UML 1 UML 2

Page 46: UML package diagrams

Component diagrams

• Component: a modular unit with well-defined interfaces

that is replaceable within its environment (UML Superstructure

Specification, v.2.0, Chapter 8)

• fosters reuse

• stresses interfaces

• Two views: black-box and white-box

• Black-box view: interfaces provided and required only

/ SET / W&I PAGE 45 24-2-2014

Page 47: UML package diagrams

Component diagrams

• Component: a modular unit with well-defined interfaces

that is replaceable within its environment (UML Superstructure

Specification, v.2.0, Chapter 8)

• fosters reuse

• stresses interfaces

• Two views: black-box and white-box

• Black-box view: interfaces provided and required only

• White-box view: structure of interfaces and/or internal

structure

/ SET / W&I PAGE 46 24-2-2014

provided

interface

required

interface

Page 48: UML package diagrams

Component diagrams

• Component: a modular unit with well-defined interfaces

that is replaceable within its environment (UML Superstructure

Specification, v.2.0, Chapter 8)

• fosters reuse

• stresses interfaces

• Two views: black-box and white-box

• Black-box view: interfaces provided and required only

• White-box view: structure of interfaces and/or internal

structure

/ SET / W&I PAGE 47 24-2-2014

Page 49: UML package diagrams

Nested components

• Components can be contained in other components

• Interfaces can then be delegated through ports

/ SET / W&I PAGE 48 24-2-2014

Page 50: UML package diagrams

Summary: UML component diagrams

/ SET / W&I PAGE 49 24-2-2014

http://www.uml-diagrams.org/component-diagrams.html

Page 51: UML package diagrams

UML structure diagrams

/ SET / W&I PAGE 50 24-2-2014

Class diagram

Composite structure diagram

Packages diagram

Component diagram

Object diagram

Deployment diagram

Page 52: UML package diagrams

Deployment

• Deployment: relationship between logical and/or

physical elements of systems (Nodes) and information

technology assets assigned to them (Artefacts).

/ SET / W&I PAGE 51 24-2-2014

Page 53: UML package diagrams

Deployment

• Deployment: relationship between logical and/or

physical elements of systems (Nodes) and information

technology assets assigned to them (Artefacts).

• Nodes

• devices: application server, client workstation, …

• execution environments: DB system, J2EE container, …

• Graphical representation: box

/ SET / W&I PAGE 52 24-2-2014

DBServer

Page 54: UML package diagrams

Deployment

• Deployment: relationship between logical and/or

physical elements of systems (Nodes) and information

technology assets assigned to them (Artefacts).

• Nodes

• devices: application server, client workstation, …

• execution environments: DB system, J2EE container, …

• Graphical representation: box

• Nodes can be physically connected (e.g., via cables or

wireless)

• UML-parlance: CommunicationPath

• Graphical representation: as an association

/ SET / W&I PAGE 53 24-2-2014

DBServer

Page 55: UML package diagrams

Deployment

• Deployment: relationship between logical and/or

physical elements of systems (Nodes) and information

technology assets assigned to them (Artefacts).

• Artefacts: information items produced during software

development or when operating the system

• model files, source files, scripts, executable files, database

tables, word-processing documents, mail messages, …

• Graphical representation: “class-like”

• Relations: dependencies

/ SET / W&I PAGE 54 24-2-2014

<<artifact>>

ShoppingCart.jar

Page 56: UML package diagrams

Deployment

• Deployment: relationship between logical and/or

physical elements of systems (Nodes) and information

technology assets assigned to them (Artefacts).

• Deployment: three equally valid representations

PAGE 55 24-2-2014 http://www.uml-diagrams.org/deployment-diagrams.html

Page 57: UML package diagrams

Deployment: missing piece

• How do we know where a given use case, class,

component, or package is deployed?

• Use case / class / component / packages diagrams do not

discuss deployment

• Deployment diagrams do not discuss use cases / classes /

components / packages but only artifacts

/ SET / W&I PAGE 56 24-2-2014

Page 58: UML package diagrams

Deployment: missing piece

• How do we know where a given use case, class,

component, or package is deployed?

• Use case / class / component / packages diagrams do not

discuss deployment

• Deployment diagrams do not discuss use cases / classes /

components / packages but only artifacts

• Manifestation maps artifacts to use

cases / classes / components /

packages

/ SET / W&I PAGE 57 24-2-2014

Page 60: UML package diagrams

Conclusions

/ SET / W&I PAGE 59 24-2-2014