+ All Categories
Home > Documents > Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 1 Introduction to UML Part 2.

Date post: 22-Dec-2015
Category:
View: 252 times
Download: 2 times
Share this document with a friend
51
Itntroduction to UML 1 Introduction to UML Part 2
Transcript
Page 1: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 1

Introductionto UMLPart 2

Page 2: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 2

Building blocks of the UMLBuilding blocks of the UML• As part of a model you have:

– 1 1 modeling elementsmodeling elements– 22 relationshipsrelationships between the modeling elements– 33 diagramsdiagrams that group and visualize the modeling elements

and the relations between them.• E.g. class diagram:

Company

Department OfficeLocatedAt

*

1

1..* 1..*

*

Page 3: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 3

11 Modeling elementsModeling elements

• You have modeling elements for:– 1.1 Structural thingsStructural things– 1.2 Behavioral thingsBehavioral things– 1.3 Grouping thingsGrouping things– 1.4 Annotational thingsAnnotational things

Page 4: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 4

1.11.1 Structural elementsStructural elements

• Identified with nouns, e.g. Person; Typically representing static parts of the model. In UML you will find 7 different types of structual elements:– 1.1.1 ClassClass– 1.1.2 InterfaceInterface– 1.1.3 Active classActive class– 1.1.4 ColloborationColloboration– 1.1.5 ComponentComponent– 1.1.6 NodeNode– 1.1.7 Use CaseUse Case

Page 5: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 5

Point

- x : int- y : int

+ getX() : int+ setX(aX : int) : void+ getY() : int+ setY(aY : int) : void

1.1.1 Class:1.1.1 Class:Describes a Set of ObjectsDescribes a Set of Objects

Pointx : inty : int

getX() : intsetX(aX : int) : voidgetY() : intsetY(aY : int) : void

Rose: The icons , and can beused instead of +, # and -

Rational Rose 2000

class name

attributes

operations

visibility

operationsignature

Page 6: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 6

Encapsulation -Encapsulation -Also Called Data HidingAlso Called Data Hiding

• Encapsulation: hiding the the implementation of the data hiding the the implementation of the data from users of the objectfrom users of the object. Users are typically objects of other classes.The users don’t see if the data is stored in fields, calculated or if they are retrieved from a database, they only call a method.

• Encapsulation is achieve by never letting objects directly never letting objects directly access fieldsaccess fields. Fields should only be accessed through the object’s methods.

• Making the fields privateMaking the fields private (or protected) ensures encapsulation. If you want objects of different types to access the fields, then make public methodspublic methods (or package accessibility) for this purpose.

Page 7: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 7

A method is an implementation of an operation.

A method specifies the algorithm or procedurethat produces the results of an operation.

Operation Versus Method Operation Versus Method (C++ member function)(C++ member function)

Page 8: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 8

1.1.2 Interface:1.1.2 Interface:A Named Set of Operations A Named Set of Operations That Describes Some Behavior That Describes Some Behavior (No Implementation)(No Implementation)

ISortable

ISortable

isEqual(otherObject : ISortable) : booleanisLess(theOther : ISortable) : booleanisGreater(theOther : ISortable) : boolean

<<Interface>>

interface - iconic form

interface name stereotype

interface - expanded form

operationcompartment

Page 9: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 9Interface, HiA by J.P.Nytun 2

An Interface Can Be Seen As a ProtocolAn Interface Can Be Seen As a Protocol

• An interfaceinterface is an agreement on behavioragreement on behavior.

• A classclass which implementsimplements an interface agrees on supporting the specified behaviorthe specified behavior.

• An interfaceinterface can also be seen as a definition of a roledefinition of a role, classes which implements the role are able to play that role.

Example: The auto-pilot of an airplane can act as a pilot the same is true about some humans. The auto-pilot and the human is quit different types of objects, but they can both play the same role. Many different types of objects can implement the interface, so the interface is not the same as a “class to subclass from”.

Page 10: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 10

1.1.3 Active Class1.1.3 Active Class

Snakepos:Point

move()bite()

Active class: describes objectsthat owns their own thread;The behavior of this objectscan be concurrent with others

Page 11: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 11

1.1.4 Colloboration1.1.4 Colloboration

Colloboration: describes a colloborationbetween roles to achieve a particular goal.A collaboration can represent animplementation of a use case or a particularpattern.

Listener

Page 12: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 12

1.1.5 Component1.1.5 Component

calculate.class

Component: a physicalpart of the system whichimplements a set of interfaces.

Page 13: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 13

Different types ofDifferent types of Components Components (in(in UML UML))• Deployment ComponentsDeployment Components: this components can be assembled to form a complete executable system.

Example: A complete executable application, a dynamic library (DLL), a JavaBean, a COM+ object.

• Work Product ComponentsWork Product Components: this components are the basis for making the deployment components. They are not a part of the executable system, but results from the development process. Example: Source code.

• Execution ComponentsExecution Components: this components are created by an executing system. Example: a JavaBean created during runtime.

Page 14: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 14

Web ExampleWeb Example

Menu

Menu.html

Menu.jpg

---------------

Menu.javaCould be an execution component,

e.g. Produced by a servelet

Deployment component

Working productcomponent

Deployment component

Page 15: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 15

1.1.6 Node1.1.6 Node

Node: a physical element that represent a computational resource(e.g. processor and memory).

videoServer

Page 16: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 16

1.1.7 Use Case1.1.7 Use Case

Use case: describes a sequence of actions that yields an observable result for an actor. With use cases you can structure the behavioral things in a model.

Registerfor exam

Page 17: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 17

Extensibility MechanismsExtensibility Mechanisms

«container»

EventQueue{version 2.1}

add(e:event)remove(n:int)«query»

length():int«helper function»

reorder()

stereotype

tagged value

{add runs in O(1) time}

constraint

Page 18: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 18

1.2 Behavioral Elements1.2 Behavioral Elements

• Describing the dynamically parts of the model. Behavioral elements are identified with the help of verbs.– 1.2.1 InteractionInteraction– 1.2.2 StateState

Page 19: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 19

1.2.1 Interaction1.2.1 Interaction

Interaction: A behavior that comprises aset of messages sent between a set of objectsto archive a special purpose, like in a sequencediagram.

User Oven-control -unit Oven-light

Set temperature(250C)

Heat on light on

Page 20: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 20

1.2.2 State Machine1.2.2 State Machine

State machine: A description of the differentstates an object can go through in response toevents. Events generated by the object is alsoshown. An activity diagram is a special case ofa state diagram.

One State An Other State

SomeEvent / SomeAction()

Page 21: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 21

1.3 Grouping Elements1.3 Grouping Elements

• You can group elements with the help of packages.

• [1]: ”A package may own other elements, including classes, ..., diagrams, and even other packages.”

• You can use packages to orginaze your classes (interfaces,..) and your diagrams.

java

applet

+Applet

Page 22: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 22

1.4 Annotational Elements1.4 Annotational Elements

• You can add comments to a diagram with the help of notes.

A comment

Page 23: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 23

2 Relations2 Relations

• You have 4 different relationships:– 2.1 DependencyDependency– 2.2 AssociationAssociation– 2.3 GeneralitationGeneralitation– 2.4 RealizationRealization

Page 24: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 24

2.1 Dependency:2.1 Dependency:

• A relationship between to modeling elements, indicate that a change in the destination may effect the source.

EmployeeCompany

add(e : employee)

The method add has an employee as argument, soCompany-class (source) is dependent of the Employee-class (destination).

Page 25: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 25

2.2 Association:2.2 Association:• This relationship indicate that there is a connection

from one type of objects to another type.An important type of association is aggregation which indicates that one object contains objects of a given type.

Company

Department OfficeLocatedAt

1

1..* 1..*

* *

composition or strong aggregation

ordinary association

multiplicity

associationname

Page 26: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 26

2.3 Generalization:2.3 Generalization:

• A relationship between a more general element and a more specific one. For example: a bird is also an animal.

Animal

Bird

A bird is a specializationof an animal.

Page 27: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 27

2.4 Realization:2.4 Realization:

• UML: ”A semantic relationships between classifiers, in which one classifiers specifies a contract that another classifier guarantees to carry out”.

”interface”

Movablemove(x,y)

Snakemove(x,y)

The class Snake implementsthe interface Movable.

Page 28: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 28

3 Diagrams3 Diagrams

• A diagram is typically a view of a part of the model, showing modeling elements and some of the relationships between them.

• A diagram do not have to be complete, some elements may be missing or presented in a simplified fashion.

• UML: ”A well-formed model is one that is semantically self-consistent and in harmony with all related models.”

Page 29: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 29

There are 9 types of diagrams inThere are 9 types of diagrams in UMLUML

SequenceDiagrams

Dynamic views Static views

CollaborationDiagrams

ActivityDiagrams

StatechartDiagrams

ClassDiagrams

ObjectDiagrams

ComponentDiagrams

DeploymentDiagrams

Use CaseDiagrams

Model

Some part ofthe model might not be visible on

any diagram

Page 30: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 30

3.1 Use case diagram3.1 Use case diagram

User

register a person

edit a registration/delete a registration

navigate/viewthe register

”include”view next

person

view previousperson

”include”

”include”

actor

association

use casesystem boundary

include relationship

Page 31: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 31

Use Case Diagram - One More ExampleUse Case Diagram - One More Example

Make/edit course Lecturer

Student Register for course

Register as studentPerson

<<become>>

Adm

Register for exam

InstructorWorking with courseCourseParticipant

<<become>>

”A use case is a specific way of usingthe system by performing somepart of the functionality.Each use case constitutes a completecourse of events initiated by an actor,and it specifies the interaction thattakes place between an actor andthe system....”

I. Jacobson

Page 32: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 32

3.2 Class Diagram3.2 Class Diagram

name : Stringdescription : String

name : Stringemail : StringhomePage : String

*

CourseModule

name : Stringdescription : String

1..*

Student StudentCourseProfile

finished : boolean

Course1 *Person

1 *tech. responsible for

1

1

**

1

*

responsible for

When a student register for course a StudentCourseProfile

object will be made!

Page 33: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 33

A Class DiagramA Class DiagramWith NavigationWith Navigation

name : Stringdescription : String

name : Stringimail : StringhomePage : String

*

CourseModule

name : Stringdescription : String

1..*

Student

Course1 *responsible forPerson

1 *tech. responsible for

1

1

1

StudentCourseProfile

finished : boolean

***

Page 34: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 34

A Class Diagram - Mapping to JavaA Class Diagram - Mapping to Java

name : Stringdescription : String

name : Stringimail : StringhomePage : String

Student

Course1 *responsible forPerson

1 *tech. responsible for

1

1

StudentCourseProfile

finished : boolean

**

public class Person { protected String name; protected String imail; protected String homePage;//// Navigation protected Course[] responsibleFor; protected Course[] techResponsibleFor;

public Person() { }}

public class Person { protected String name; protected String imail; protected String homePage;//// Navigation protected Course[] responsibleFor; protected Course[] techResponsibleFor;

public Person() { }}

public class Student extends Person {//// Navigation public StudentCourseProfile[] studentCourseProfile;

public Student() { }}

public class Student extends Person {//// Navigation public StudentCourseProfile[] studentCourseProfile;

public Student() { }}

Page 35: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 35

A Class Diagram - Example With InterfaceA Class Diagram - Example With Interface

Person

edit()write()read()

RegisterIStorable

edit()write()read()

<<Interface>>

0..*

-reg

0..*

public void read(){ terminal.print("Name: ");

name = terminal.readLine(); ...}

relization

Person

edit()write()read()Storable

Register

relization/implements

dependency

To different representationof nearly the same

Page 36: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 36

A Class Diagram -A Class Diagram -One More Example With InterfaceOne More Example With Interface

Person

IStorableRegister

ISortable

isLess(theOther : ISortable) : booleanisEqual(theOther : ISortable) : booleanisGreater(theOther : ISortable) : boolean

<<Interface>>

SortableRegister

Page 37: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 37

3.3 Object Diagram -3.3 Object Diagram -Capture Instances and LinksCapture Instances and Links

Company

Class Object

Possible object

name

noOfEmploees : intHiA: Company

noOfEmploees=600

object classattributewith value

Page 38: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 38

Object Diagram with LinksObject Diagram with Links

HiA: Company

Engineering : Department

Grooseveien:Office

:LocatedAt

Language: Department

Gimlemoen:Office

:LocatedAtCompany

Department OfficeLocatedAt

1

1..*

1..**

Class Diagram Object Diagram

Possibleobject diagram

Link - A link is an instance of an association,analogous to an object being an instance of a class.

Page 39: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 39

HiA:Comany Gimlemoen:Office

noOfEmploees = 600

Object diagram and Rational Rose 2000Object diagram and Rational Rose 2000

Rational Rose 2000 does not have object diagrams,but you can achieve much the same with a collobartion diagram

You can not specify attributes inside object;One solution to this short-coming is to use a comment!

Page 40: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 40

3.4 Sequence diagram3.4 Sequence diagram

<name,e-mail,..>

<command r>

registeruser controllerViewer

person”create”

insert(person)

setData(name, ..)

Page 41: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 41

3.5 Colloboration diagram3.5 Colloboration diagram

register

personuser

1: register()

controllerViewer

1.1: data := getData()

1.3: setDate(data)1.2: ”create”

1.4: insert(person)

Page 42: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 42

3.6 Statechart diagram 3.6 Statechart diagram

StateChart for microwaveoven "control unit"

Simple microwave oven:- Power can be on or off- Time can be set after the power has been turned on

Waiting

do/ display("Off")exit/ display("Time?")

Set time

do/ get numberexit/ ^timer.setTime(timeRead)

Disabled

do/ display("Close Door")

Operating

do/ display ("time left")exit/ ^heattingElement.powerOff()entry/ ^heatingElement.powerOn()

[ Door open ] [ Door closed ]

Door closed

Door open

End

Time out

Power turned on

Page 43: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 43

Statechart for AppletStatechart for Applet

init/init()

start/start()

NotLoaded

Loaded

Running

destroy/destroy()

stop/stop()

start/start()

Stopped

Page 44: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 44

3.7 Activity diagram -3.7 Activity diagram -Capture Dynamic Behaviour (Activity-oriented)Capture Dynamic Behaviour (Activity-oriented)

Page 45: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 45

Activity diagram -Activity diagram -One More ExampleOne More Example

activity

product of activity

Page 46: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 46

Activity diagram - One More ExampleActivity diagram - One More Exampleuser controller person register

request registration

create person (object)

supply person-data

forward person-data

process person-data

insert person

Page 47: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 47

3.8 Component diagram -3.8 Component diagram -Captures the Physical Structure of the ImplementationCaptures the Physical Structure of the Implementation

applet1.class

Demo.html applet2.class

logo.gif

applet1.java

applet2.java

Page 48: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 48

Component diagram -Component diagram -One More ExampleOne More Example

Person.class Register.class

ISortable

Page 49: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 49

3.9 Deployment diagram3.9 Deployment diagram

ExtendedVLAN

”network” LAN

”PC””PC”

”Server”

Page 50: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 50

server1:

client:

Multi-tier Architecture

- MVC -view:

browser/jsp/servletcontroller:jsp/servletmodel:

businessObjects

j1:Jsp s1:Servlet

server2:

browser:InternetInternet

:WebServer

:DB

:ServletContainer

s2:Servlet j2:Jsp

b1:BusinessObject b3:BusinessObject

b4:BusinessObject b2:BusinessObject

IntranetIntranet

:html:html

Page 51: Itntroduction to UML 1 Introduction to UML Part 2.

Itntroduction to UML 51

ReferencesReferences• [1] Grady Booch, James Rumbaugh and Ivar Jacobson:

The Unified Modeling Language User Guide.Addison-Wesley, 1999

• James Rumbaugh, Michael Blaha, William Premerlani, Frederick Eddy and William Lorenzen: Object-Oriented Modeling and Design. Prentice Hall, 1991

• Martin Fowler with Kendall Scott: UML Distilled.Addison-Wesley, 1997

• Terry Quatrani: Visual Modeling with Rational Rose and UML.Addison-Wesley, 1998

• Ari Jaaksi: A Method for Your First Object-Oriented Project. JOOP - The Journal of Object-Oriented Programming, Januar 1998

• Rational software: http://www.rational.com/uml/documentation.html


Recommended