56
ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

  • View
    218

  • Download
    2

Embed Size (px)

Citation preview

Page 1: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Bouwkundige InformatiesystemenADMS 2006

UML part 2

Bouwkundige InformatiesystemenADMS 2006

UML part 2

Jan Dijkstra - 23 oktober 2006

Page 2: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

SubjectsSubjects

• Objects & ClassesObjects & Classes 16 16 oktokt..

• UML : Class Diagram 23 okt..• UML : Object Diagram 23 okt..• UML : Class Diagrams Exercises 23 okt.

• Exercise Class Diagram MKWExercise Class Diagram MKW 23 okt23 okt..• Discussion Exercise Class Diagram MKWDiscussion Exercise Class Diagram MKW 30 okt.30 okt.

• UML : Class Diagrams - Advanced ConceptsUML : Class Diagrams - Advanced Concepts 30 okt.30 okt.

• Task UML-part 2Task UML-part 2 30 okt.30 okt.

Page 3: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

UML Models, Views and DiagramsUML Models, Views and Diagrams

• A diagram is a view into a model– presented from the aspect of a particular stakeholder– and provides a partial representation of the system

Page 4: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

UML ViewsUML Views

Design view

Interaction view

Implementa-tion view

Deployment view

Use Case view

vocabularyfunctionality

behaviour

performancescalabilitythroughput

system assemblyconfiguration management

system topologydistributiondeliveryinstallation

physicallogical

Design view

Interaction view

Implementa-tion view

Deployment view

Use Case view

Page 5: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

UML DiagramsUML Diagrams

• Structure diagram– Class diagram– Object diagram– Component diagram– Composite structure

diagram– Deployment diagram– Artifact diagram

• Behaviour diagram– Use Case diagram– Sequence diagram– Communication diagram– State diagram– Activity diagram

Page 6: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Use Case diagramUse Case diagram

Page 7: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Classes/objects “course management”Classes/objects “course management”

CourseCustomer

Reservation

Page 8: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

UML Class DiagramsUML Class Diagrams

The class diagram provides a static structure of all the classes that exist within the system. Classes are arranged in hierarchies sharing common structure and behaviour and are associated with other classes.

Class diagrams are used in:• Analysis To build a conceptual domain model with

semantic associations between concepts• •

Page 9: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Class Diagram: associations between classesClass Diagram: associations between classes

CourseCustomer

Reservation

Page 10: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Classes and ObjectsClasses and Objects

An object is described by a classobject is described by a class.

A class may define a number of objects with identical properties

Page 11: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Object Diagram: links between objectsObject Diagram: links between objects

cname:Coursecust1:Customer

res22:Reservation

Page 12: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Class diagramClass diagram

A class diagram describes the type of objects in a system and the static relationships between them.

•Static relations:– Associations– Subtypes

•Static structure:– Attributes– Operations

Page 13: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

ClassClass

• A class is a set of objects that share the same properties.

 

 

Name

Page 14: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

ClassClass

• A class is a set of objects that share the same properties.

• A class has a name.

 

 

Course

Page 15: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Class - attributesClass - attributes

• The class captures the abstraction of properties in the set of objects.

 

 

Name

AttributesAttributes

Page 16: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Class - attributesClass - attributes

• An attribute of a class is identified by name, and it identifies a property of the objects of the class, for which each object takes a value.

• A class has 0 to n attributes.

 

 

CourseCourse

courseNum: Integertitle: Stringdatum: Date

Page 17: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Class - operationsClass - operations

 

OrderOrder

Attributes Attributes

OperationsOperations

• Operations are the processes that a class knows to carry out.

Page 18: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Class - operationsClass - operations

• The operations are the ‘responsibilities’ – the things we can ask an object to do.

• A class has 0 to n operations.

CourseCourse

courseNum: Integertitle: Stringdatum: Date

addReservation()cancel()

Page 19: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

UML Class DiagramsUML Class Diagrams

Class diagrams are used in:• Analysis To build a conceptual domain model with semantic

associations between concepts• Design Structural model of a design in terms of class interfaces• Implementation Source code documentation, exposing the

implementation

The class diagram provides a static structure of all the classes that exist within the system. Classes are arranged in hierarchies sharing common structure and behaviour and are associated with other classes.

Page 20: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Classes and ObjectsClasses and Objects

• Objects looks like modules in some ways

Object = Identity + State + BehaviourObject = Identity + State + Behaviour• Objects provide encapsulation of data• An object is described by a classobject is described by a class. A class may define a

number of objects with identical properties

Page 21: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

About an ObjectAbout an Object

• An object has a public interface defining the operationsoperations (methods) it will support

• An object has private data called attributesattributes, which only its own operations can access

• An object can have private operations for its own use• An object may know about other objects by means of

associationsassociations

Page 22: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Classes - recapitulationClasses - recapitulation

A class is simply represented as a box with the name of the class inside– The diagram may also show the attributes and operations

Rectangle Rectangle

heightwidth

Rectangle

heightwidth

getArearesize

Rectangle

height: intwidth: int

getArea(): intresize(int,int)

The complete signature of an operation is: operationName(parameterName: parameterType …): returnType

Page 23: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Page 24: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Essentials of UML Class Diagramsrecapitulation

Essentials of UML Class Diagramsrecapitulation

The main symbols shown on class diagrams are:• Classes

– Represent the types of data themselves

• Associations– Represent linkages between instances of classes

• Attributes– Are simple data found in classes and their instances

• Operations– Represent the functions performed by the classes and their

instances

• Generalizations– Group classes into inheritance hierarchies

Page 25: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Page 26: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Identifying objects ?Identifying objects ?

A possible recipe

– We can identify objects in our problem context by looking for nouns and noun phrases

– Each of these can be underlined and becomes a candidate for an object in our solution

– Eliminate irrelevant objects

• Redundant, vague, event, outside scope, attribute, meta-language

Page 27: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

The Bank Account ExampleThe Bank Account ExampleThe Bank Account ExampleThe Bank Account Example

You are asked to design a system to handle current and savings accounts for a bank. Accounts are assigned to one or more customers, who may make deposits or withdraw money. Each type of account earns interest on the current balance held in it. Current accounts may have negative balances (overdrafts) and then interest is deducted. Rates of interest are different for each type of account. On a savings account, there is a maximum amount that can be withdrawn in one transaction.

Bank employees may check any account that is held at their branch. They are

responsible for invoking the addition of interest and for issuing statements at

the correct times.

A money transfer is a short lived record of an amount which has been debited

from one account and has to be credited to another. A customer may create

such a transfer from their account to any other. Transfers within a branch

happen immediately, while those between branches take three days.

Page 28: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

The Bank Account ExampleThe Bank Account ExampleThe Bank Account ExampleThe Bank Account Example

You are asked to design a system to handle current and savings accounts for a bank. Accounts are assigned to one or more customers, who may make deposits or withdraw money. Each type of account earns interest on the current balance held in it. Current accounts may have negative balances (overdrafts) and then interest is deducted. Rates of interest are different for each type of account. On a savings account, there is a maximum amount that can be withdrawn in one transaction.

Bank employees may check any account that is held at their branch. They are

responsible for invoking the addition of interest and for issuing statements at the correct

times.

A money transfer is a short lived record of an amount which has been debited from one

account and has to be credited to another. A customer may create such a transfer from

their account to any other. Transfers within a branch happen immediately, while those

between branches take three days.

Question ? Recognize the nouns!

Page 29: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

You are asked to design a system to handle current and savings accounts for a bank.

Accounts are assigned to one or more customers, who may make deposits or withdraw

money. Each type of account earns interest on the current balance held in it. Current

accounts may have negative balances (overdrafts) and then interest is deducted. Rates of

interest are different for each type of account. On a savings account, there is a maximum

amount that can be withdrawn in one transaction.

Bank employees may check any account that is held at their branch. They are responsible

for invoking the addition of interest and for issuing statements at the correct times.

A money transfer is a short lived record of an amount which has been debited from one

account and has to be credited to another. A customer may create such a transfer from

their account to any other. Transfers within a branch happen immediately, while those

between branches take three days.

Nouns in the bank account example

Page 30: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

RedundantRedundant - overdraft, account

VagueVague - amount, money

An event or an operationAn event or an operation - transaction, deposit

Outside scope of systemOutside scope of system - bank, days

An attributeAn attribute - interest, rate of interest, maximum amount, current balance, overdraft

Meta-languageMeta-language - transaction, correct times, record

Nouns eliminatedNouns eliminated

Page 31: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Nouns leftNouns left

• current account, savings account, customer, branch, statement, transfer

Remark:

The Bank Account is derived from

Pauline Wilcox – ‘The Unified Modelling Language’ in

Msc in Systems Level Integration – Systems Partitioning Module

Page 32: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Class Diagram (without adornments)bank account example

Class Diagram (without adornments)bank account example

Customer

Current Account

Branch

Savings Account

Transfer

Statement

• current account,

• savings account,

• customer,

• branch,

• statement,

• transfer

Page 33: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Association Adornments: Name, RoleAssociation Adornments: Name, Role• The association has a name - the descriptive term, often a

verb, for the association.

• Each association has two association ends; each end is attached to one of the classes in the association. An end can be explicitly named with a label. This label is called a role name (association ends are often called roles).

Person Company

employee employer

works for

Person Company

employee employer

has employment for

Page 34: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Association: MultiplicityAssociation: Multiplicity

Multiplicity defines the number of objects associated with an instance of the association.– Default of 1 (1: 1)– 0 or 1: 0..1– Zero or more (0..infinite): *– 1 or more (1..infinite): 1..*– n..m; range from n to m

inclusive

Car Persontransports

passenger

Car Persontransports

passenger

5

Car Persontransports

passenger

*

Car Persontransports

passenger

1..*

Car Persontransports

passenger

2..5

Page 35: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Class Diagram (with multiplicities)bank account example

Class Diagram (with multiplicities)bank account example

Customer

Current Account

Branch

Savings Account

Transfer

Statement

Customer

Current Account

Branch

Savings Account

Transfer

Statement

1

0..*

1

0..*

0..*

1 1

0..*1

1 1

11

1 1

1

Page 36: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Association classesAssociation classes

Sometimes an attribute that concerns two associated classes cannot be placed in either of the classes

Student CourseSection* *

Registration

grade

Student CourseSectionRegistration

grade* *

Page 37: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Attribute AnalysisAttribute Analysis

It is not always clear which attributes belongs to which classes by finding out the class attributes. An attribute is assigned to that class where it is certainly a feature.

For example:

a project leader has the attributes name, department and age.

But what to do with the attributes project number, project duration, starting time, and budget? These attributes clarifies something about the relation between project leader and type of project.

This often happens if a n:m relation refers to an association between two classes. In that case, we can define a new class, for instance project management.

Page 38: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

-name-department-age

Project leader-project number-starting time-duration-budget

Project

-name-department-age

Project leader-project number-starting time-duration-budget

Project

* *

-starting time-final time

Management

1

*

1

*

Page 39: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

GeneralizationGeneralization

A specialization / generalization relationship, in which objects of the specialized element (child) are substitutable for objects of the generalized element (parent).• Superclass – the generalization of another class, the child.• Subclass – the specialization of another class, the parent.

Customer

Corporate

Customer

Personal

Customer

Page 40: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Generalization - characteristicsGeneralization - characteristics

• Identify common features concerning behaviour and knowledge. Define these common features on a higher level in the inheritance hierarchy.

• The aim is at behaviour more than knowledge when combining classes.

• Generalization is a bottum-up process.

• A superclass includes all common properties of its subclasses.

Page 41: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Specialization - characteristicsSpecialization - characteristics

• Define a new class which is a special appearance of an existing class.

• Specialization is a top-down process.

• A subclass can have attributes and operations that are specific for that sub-class.

• A subclass may redefine operations of its super-class.

Page 42: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Page 43: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Associations vs. generalizationsAssociations vs. generalizations

Associations describe the relationships that will exist between instances at run time– when you show an instance diagram generated from a class

diagram, there will be an instance of both classes joined by an association

Generalizations describe relationships between classes in class diagrams– they do not appear in instance diagrams at all– an instance of any class should also be considered to be an

instance of that class’s super classes

Page 44: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

AggregationAggregation

Aggregations are special associations that represent ‘part-whole’ relationships– the ‘whole’ side is often called the assembly or the aggregate

Vehicle VehiclePart*

Country Region*

Page 45: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

CompositionComposition

A composition is a strong kind of aggregation– if the aggregate is destroyed, then the parts are destroyed

as well

Building Room*

Page 46: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Aggregation and Composition: exampleAggregation and Composition: example

A B

Question: What is OK?1. A2. B3. A & B4. None

Page 47: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Object diagramObject diagram

An object diagram is shown as a class, and the name is underscored, although an object’s name can be shown optionally preceding the class name as:

objectname: classname.

The object does not have to be named, in which case only the classname is shown underscored.

Page 48: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Object diagram : exampleObject diagram : example

Computer

name: Stringmemory: String

Author

name: Stringage: Integer

0..* 1..*

Page 49: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Object diagram : exampleObject diagram : example

Computer

name: Stringmemory: String

Author

name: Stringage: Integer

0..* 1..*

Brian’s PC: Computer

name = “Dell 486”memory = “256MB”

Brian: Author

name = “Brain Jones”age = 35r

Brian’sLaptop: Computer

name = “Toshiba CT”memory = “512MB”

Page 50: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

ReferencesReferences

• Sommerville, Ian (2001)

Software Engineering, 6th edition http://www.software-engin.com

• Timothy Lethbridge & Robert Laganière (2005)

Object-Oriented Software Engineering, 2nd editionhttp://www.lloseng.com

• Martin Fowler (2000, 2004)

Object-Oriented Software Engineering, 2nd edition; 3rd edition

Page 51: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

NS Ticket serviceNS Ticket service

• Make a class diagram of ‘NS ticket service’ including the classes ‘Ticket’ and ‘Destination’

Take ticket

Destination

Page 52: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Use Case diagram ‘NS Ticket service’Use Case diagram ‘NS Ticket service’

Traveller

Buy OV ticket

Buy NS ticket

Pay ticket

«extends»

«uses»

Page 53: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Use Case Buy OV Ticket

Actors Traveller

Preconditions Traveller has a valid pass

Description 1. Ticket device expects destination code

2. Traveller enters destination code

3. Extension point: NS ticket

4. Ticket device checks code and calculates the charge. Shows destination code & fare. Activates ticket machine for paying

5. Traveller pays (use case: Pay ticket)

6. Ticket device print and supplies ticket

7. Traveller takes ticket

Extension Destination code = NS station.

3a. Ticket device expects ticket type

3b. Traveller enters Single/Return, Discount Y/N, Class

Exceptions Traveller interrupt the interaction or walk away

Traveller enters an incorrect destination code

Payment is not finished off successful

Result Traveller has ticket.

(NS can look forward to the payment)

Page 54: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Make a class diagram of ‘NS ticket service’ including the classes ‘Ticket’ and ‘Destination’

Make a class diagram of ‘NS ticket service’ including the classes ‘Ticket’ and ‘Destination’

+create()+payPrice()+printTicket()

-fromStation-toStation-oneWay : Boolean-reduction : Boolean-class-date : Date-price

Ticket

+validateDestination()+showPrice()

-code-name-distance-base price

Destination

1*

Page 55: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Exercises NowExercises Now

Page 56: ADMS-BIS Bouwkundige Informatiesystemen ADMS 2006 UML part 2 Jan Dijkstra - 23 oktober 2006

AD

MS

-BIS

Exercise 30 OctoberExercise 30 October

Ga uit van de MKW beschrijving van oefening van UML1

• Identificeer enkele klassen

• Geef zo mogelijk relaties tussen klassen aan