51
UML Diagrams Computer Science I

UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Embed Size (px)

Citation preview

Page 1: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

UML Diagrams

Computer Science I

Page 2: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Unified Modeling Language Unified Modeling Language (UML) is a

standardized general-purpose modeling language in the field of software engineering. The standard is managed, and was created by, the Object Management Group.

UML includes a set of graphic notation techniques to create visual models of software-intensive systems.

Page 3: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Structure Diagrams Structure diagrams emphasize the things that

must be present in the system being modeled. Since structure diagrams represent the structure they are used extensively in documenting the architecture of software systems.

Class diagram: describes the structure of a system by showing the system's classes, their attributes, and the relationships among the classes.

Component diagram: describes how a software system is split up into components and shows the dependencies among these components.

Page 4: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Structure Diagrams Composite structure diagram: describes the internal

structure of a class and the collaborations that this structure makes possible.

Deployment diagram: describes the hardware used in system implementations and the execution environments and artifacts deployed on the hardware.

Object diagram: shows a complete or partial view of the structure of a modeled system at a specific time.

Package diagram: describes how a system is split up into logical groupings by showing the dependencies among these groupings.

Page 5: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Structure Diagrams Profile diagram: operates at the metamodel level to

show stereotypes as classes with the <<stereotype>> stereotype, and profiles as packages with the <<profile>> stereotype. The extension relation (solid line with closed, filled arrowhead) indicates what metamodel element a given stereotype is extending.

Page 6: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Behavior Diagrams Behavior diagrams emphasize what must happen in the

system being modeled. Since behavior diagrams illustrate the behavior of a system, they are used extensively to describe the functionality of software systems.

Activity diagram: describes the business and operational step-by-step workflows of components in a system. An activity diagram shows the overall flow of control.

UML state machine diagram: describes the states and state transitions of the system.

Use case diagram: describes the functionality provided by a system in terms of actors, their goals represented as use cases, and any dependencies among those use cases.

Page 7: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Interaction Diagrams Interaction diagrams, a subset of behaviour

diagrams, emphasize the flow of control and data among the things in the system being modeled:

Communication diagram: shows the interactions between objects or parts in terms of sequenced messages. They represent a combination of information taken from Class, Sequence, and Use Case Diagrams describing both the static structure and dynamic behavior of a system.

Interaction overview diagram: provides an overview in which the nodes represent interaction diagrams.

Page 8: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Interaction Diagrams Sequence diagram: shows how objects communicate

with each other in terms of a sequence of messages. Also indicates the lifespans of objects relative to those messages.

Timing diagrams: are a specific type of interaction diagram, where the focus is on timing constraints.

Page 9: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Class Diagrams The main building block in object oriented

modeling They are used both for general conceptual

modeling of the systematics of the application, and for detailed modeling translating the models into programming code

The classes in a diagram represent both the main objects and/or interactions in the application and the objects to be programmed

In the diagram these classes are represented with boxes which contain three parts

Page 10: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Class Diagrams A class with three sections.

The upper part holds the name of the class The middle part contains the attributes of the class The bottom part gives the methods or operations the class

can take or undertake

Page 11: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Class Diagrams In the system design of a system, a number of classes

are identified and grouped together in a class diagram which helps to determine the static relations between those objects

With detailed modeling, the classes of the conceptual design are often split in a number of subclasses

In order to further describe the behavior of systems, these diagrams can be complemented by state diagram or UML state machine

Also instead of class diagrams, Object role modeling can be used if you just want to model the classes and their relationships

Page 12: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

The class icon Defines

Persistent system state

System behavior The class icon has

Name Attributes Operations

It’s a rectangle divided into three compartments.

Page 13: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Steps followed Draw class symbol in the editor

and name it List the class attributes List the class operations/methods Make the links and associations Give notations

Page 14: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Construct Description Syntax

class a description of a set of objects that share the same attributes, operations, methods, relationships and semantics.

interface a named set of operations that characterize the behavior of an element.

component a modular, replaceable and significant part of a system that packages implementation and exposes a set of interfaces.

node a run-time physical object that represents a computational resource.

«interface»

Structural Modeling: Core Elements

Reference: OMG tutorial on UML by Cris Kobryn

Page 15: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Structural Modeling: Core Elements (cont’d)

Construct Description Syntax

constraint¹ a semantic condition or restriction.

{constra in t}

¹ An extension mechanism useful for specifying structural elements.

Reference: OMG tutorial on UML by Cris Kobryn

Page 16: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Construct Description Syntax

association a relationship between two or more classifiers that involves connections among their instances.

aggregation A special form of association that specifies a whole-part relationship between the aggregate (whole) and the component part.

generalization a taxonomic relationship between a more general and a more specific element.

dependency a relationship between two modeling elements, in which a change to one modeling element (the independent element) will affect the other modeling element (the dependent element).

Structural Modeling: Core Relationships

Reference: OMG tutorial on UML by Cris Kobryn

Page 17: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Construct Description Syntax

realization a relationship between a specification and its implementation.

Structural Modeling: Core Relationships (cont’d)

Reference: OMG tutorial on UML by Cris Kobryn

Page 18: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Interfaces: Longhand Notation

Fig. 3-29, UML Notation Guide

+create()+login(UserNam e, Passwd)+find(StoreId)+getPOStotals(POSid)+updateStoreTotals(Id,Sales)+get(Item )

-storeId: Integer-POSlist: List

Store

POSterm inal

POSterm inalHom e

<<use>>

StoreHom e

POSterm inal

+getPOStotals(POSid)+updateStoreTotals(Id,Sales)+get(Item )

<<interface>>Store

Reference: OMG tutorial on UML by Cris Kobryn

Page 19: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Associations An Association represents

a family of links Binary associations (with

two ends) are normally represented as a line, with each end connected to a class box

Higher order associations can be drawn with more than two ends; in such cases, the ends are connected to a central diamond

Fig. 3-40, UML Notation Guide

Reference: OMG tutorial on UML by Cris Kobryn

Person

Manages

JobCompany

boss

worker

employeeemployer

0..1

Job

Account

Person

Corporation

{Xor}

salary

Page 20: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Associations An association can be

named, and the ends of an association can be adorned with role names, ownership indicators, multiplicity, visibility, and other properties

There are five different types of association; bi-directional and uni-directional associations are the most common ones

Fig. 3-40, UML Notation Guide

Reference: OMG tutorial on UML by Cris Kobryn

Person

Manages

JobCompany

boss

worker

employeeemployer

0..1

Job

Account

Person

Corporation

{Xor}

salary

Page 21: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Aggregations

Aggregation is a variant of the "has a" or association relationship; aggregation is more specific than association

It is an association that represents a part-whole or part-of relationship. As a type of association, an aggregation can be named and have the same adornments that an association can

However, an aggregation may not involve more than two classes

Page 22: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Aggregations

Aggregation can occur when a class is a collection or container of other classes, but where the contained classes do not have a strong life cycle dependency on the container—essentially, if the container is destroyed, its contents are not

In UML, it is graphically represented as a hollow diamond shape on the containing class end of the tree of lines that connect contained class(es) to the containing class

Page 23: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Composition Composition is a stronger variant of the

"owns a" or association relationship; composition is more specific than aggregation

It is represented with a solid diamond shape Has a strong life cycle dependency between

instances of the container class and instances of the contained class(es): If the container is destroyed, normally every instance that it contains is destroyed as well

Note that a part can (where allowed) be removed from a composite before the composite is deleted, and thus not be deleted as part of the composite

The UML graphical representation of a composition relationship is a filled diamond shape on the containing class end of the tree of lines that connect contained class(es) to the containing class

Fig. 3-45, UML Notation GuideReference: OMG tutorial on UML by Cris Kobryn

Window

scrollbar [2]: Slidertitle: Headerbody: Panel

Window

scrollbar title body

Header Panel

2 1 1

Slider

111

Page 24: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Generalization Indicates that one of the two

related classes (the subtype) is considered to be a specialized form of the other (the super type) and supertype is considered as 'Generalization' of subtype

In practice, this means that any instance of the subtype is also an instance of the supertype

An exemplary tree of generalizations of this form is found in binomial nomenclature: human beings are a subtype of simian, which are a subtype of mammal, and so on. The relationship is most easily understood by the phrase 'A is a B' (a human is a mammal, a mammal is an animal).

Fig. 3-47, UML Notation Guide Reference: OMG tutorial on UML by Cris Kobryn

Shape

SplineEllipsePolygon

Shape

SplineEllipsePolygon

Shared Target Style

Separate Target Style

. . .

. . .

Page 25: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Generalization The UML graphical

representation of a Generalization is a hollow triangle shape on the supertype end of the line (or tree of lines) that connects it to one or more subtypes.

The generalization relationship is also known as the inheritance or "is a" relationship.

The supertype in the generalization relationship is also known as the "parent", superclass, base class, or base type.

The subtype in the specialization relationship is also known as the "child", subclass, derived class, derived type, inheriting class, or inheriting type.

Fig. 3-47, UML Notation Guide Reference: OMG tutorial on UML by Cris Kobryn

Shape

SplineEllipsePolygon

Shape

SplineEllipsePolygon

Shared Target Style

Separate Target Style

. . .

. . .

Page 26: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Generalization Note that this relationship

bears no resemblance to the biological parent/child relationship: the use of these terms is extremely common, but can be misleading

Generalization-Specialization relationship

A is a type of B E. g. "an oak is a type of tree",

"an automobile is a type of vehicle"

Generalization can only be shown on class diagrams and on Use case diagrams.

Fig. 3-47, UML Notation Guide Reference: OMG tutorial on UML by Cris Kobryn

Shape

SplineEllipsePolygon

Shape

SplineEllipsePolygon

Shared Target Style

Separate Target Style

. . .

. . .

Page 27: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Dependencies Dependency is a

weaker form of relationship which indicates that one class depends on another because it uses it at some point of time

It exists if a class is a parameter variable or local variable of a method of another classFig. 3-50, UML Notation Guide

Reference: OMG tutorial on UML by Cris Kobryn

«friend»ClassA ClassB

ClassC

«instantiate»

«call»

ClassD

operationZ()«friend»

ClassD ClassE

«refine»ClassC combines

two logical classes

Page 28: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

UML Class Diagram Examples

Reference: www.smartdraw.com

Page 29: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the
Page 30: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the
Page 31: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the
Page 32: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the
Page 33: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the
Page 34: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Object Diagram A diagram that shows

a complete or partial view of the structure of a modeled system at a specific time

Focuses on some particular set of object instances and attributes, and the links between the instances

Page 35: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Object Diagram A set of objects (instances

of classes) and their relationships

A static snapshot of a dynamic view of the system

Represents real or prototypical cases

Very useful before developing class diagrams

Worth saving as elaborations of class diagrams

Page 36: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Instance Specifications Each object and link is represented by an

Instance Specification This can show an object's classifier (e.g. an

abstract or concrete class) and instance name, as well as attributes and other structural features using slots

Each slot corresponds to a single attribute or feature, and may include a value for that entity

Page 37: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Instance Specifications The name on an instance specification

optionally shows … an instance name,

a ':' separator, and optionally one or more classifier names separated by commas

The contents of slots, if any, are included below the names, in a separate attribute compartment

A link is shown as a solid line, and represents an instance of an association

Page 38: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Example

As an example, consider one possible way of modeling production of the Fibonacci sequence

Page 39: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Example

In the first UML object diagram, the instance in the leftmost instance specification …

is named v1, has IndependentVariable as its classifier, plays the NMinus2 role within the FibonacciSystem,

and has a slot for the val attribute with a value of 0

Page 40: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Example

The second object … is named v2, is of class IndependentVariable, plays the NMinus1 role, and has val = 1

Page 41: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Example

The DependentVariable object … is named v3, and plays the N role

Page 42: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Example

The topmost instance, an anonymous instance specification, …

has FibonacciFunction as its classifier, and may have an instance name, a role, and slots, but

these are not shown here

Page 43: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Example

The diagram also includes three named links, shown as lines

Links are instances of an association

Page 44: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Example

After the first iteration, when n = 3, and f(n-2) = 1, and f(n-1) = 1, then f(n) = 1 + 1 = 2

At a slightly later point in time, the IndependentVariable and DependentVariable objects are the same, but the slots for the val attribute have different values

The role names are not shown here

Page 45: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Example

After several more iterations, when n = 7, and f(n-2) = 5, and f(n-1) = 8, then f(n) = 5 + 8 = 13

In a still later snapshot, the same three objects are involved

Their slots have different values The instance and role names are not shown

here

Page 46: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

Usage If you are using a UML modeling tool, you will

typically draw object diagrams using some other diagram type, such as on a class diagram

An object instance may be called an instance specification or just an instance

A link between instances is generally referred to as a link

Other UML entities, such as an aggregation or composition symbol (a diamond) may also appear on an object diagram

Page 47: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

More Examples

Class diagram

Object diagram

Page 48: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

More Examples What does this

object diagram tell us?

Page 49: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

More Examples What would the class

diagram look like that goes along with this object diagram?

Page 50: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

More Examples Does this make

sense to you?

Page 51: UML Diagrams Computer Science I. Unified Modeling Language Unified Modeling Language (UML) is a standardized general-purpose modeling language in the

More Examples