91
1 Object Oriented Analysis and Design with UML UNIT 2

1 Object Oriented Analysis and Design with UML UNIT 2

Embed Size (px)

Citation preview

Page 1: 1 Object Oriented Analysis and Design with UML UNIT 2

1

Object OrientedAnalysis and Design

with UML

UNIT 2

Page 2: 1 Object Oriented Analysis and Design with UML UNIT 2

2

Summary Unit 1...

Object-Oriented Approach– Is structured in terms of

• Objects (state + behaviour + identity)

• Messages

• Methods

– Supports sharing through• Classes and instances

• Class hierarchies

Page 3: 1 Object Oriented Analysis and Design with UML UNIT 2

3

Summary Unit 1...Object-Oriented Techniques

» Are based on– Encapsulating data and procedures

– Inheritance

– Polymorphism

» Facilitate– Modularity

– Reusability and sharing

– Extensibility and change (maintainability)

Page 4: 1 Object Oriented Analysis and Design with UML UNIT 2

4

Summary Unit 1.

Needfor a

Strategy

Analysis

Design

Implementation Testing

ExploitationMaintenance

Problem

Page 5: 1 Object Oriented Analysis and Design with UML UNIT 2

5

TheUnified

ModellingLanguage

UNIT 2

Page 6: 1 Object Oriented Analysis and Design with UML UNIT 2

6

Unit 2 : Outline

The History of the UML General overview of the UML Use Case Diagram Class Diagram

Page 7: 1 Object Oriented Analysis and Design with UML UNIT 2

7

Unit 2 : Outline

The History of the UML General overview of the UML Use Case Diagram Class Diagram

Page 8: 1 Object Oriented Analysis and Design with UML UNIT 2

8

Unified Modeling Language

Designed by G. Booch, J. Rumbaugh, I. Jacobson (3 amigos)– Started in 1994, version 1.0 finished in 1997

– They put aside their own methods and notations

To end the OO method wars– Lack of standardization : every method, tool, practice

has their own set of symbols and terminology

Became the formal and de facto standard

Page 9: 1 Object Oriented Analysis and Design with UML UNIT 2

9

The Evolution of UMLNov ‘97 UML approved by the OMG

Page 10: 1 Object Oriented Analysis and Design with UML UNIT 2

10

Contributions to the UML

Meyer

Before and after conditions

Harel

StatechartsGamma, et al

Frameworks and patterns,

HP Fusion

Operation descriptions and message numbering

Embley

Singleton classes andhigh-level view

Wirfs-Brock

Responsibilities

Odell

Classification

Shlaer - Mellor

Object lifecycles

Rumbaugh

OMT

Booch

Booch method

Jacobson

OOSE

Page 11: 1 Object Oriented Analysis and Design with UML UNIT 2

11

Unit 2 : Outline

The History of the UML General overview of the UML Use Case Diagram Class Diagram

Page 12: 1 Object Oriented Analysis and Design with UML UNIT 2

12

Why would you use UML To learn OO

– CRC cards Class-Responsibility-Collaboration

– Class diagrams

– Interaction diagrams

– Design patterns

Communicate with domain experts– Use cases

– Class diagrams (conceptual)

– Activity diagrams

Page 13: 1 Object Oriented Analysis and Design with UML UNIT 2

13

General Goals of UML

Model systems using OO concepts

Technical Systems

Information Systems

Software Systems

System Software

Distributed Systems

Real-time Systems

Business Systems …

Establish an explicit coupling to conceptual as well as executable artefacts

To create a modelling language usable by both humans and machines

Page 14: 1 Object Oriented Analysis and Design with UML UNIT 2

14

Different Types of Systems… Information Systems

– Store, retrieve, transform, present information to users

– Large amounts of data, complex relationships, stored in databases

Technical Systems– Handle, control technical equipment

– Special interfaces e.g. for telecommunications, military systems, industrial processes

– Real-time

Page 15: 1 Object Oriented Analysis and Design with UML UNIT 2

15

Different Types of Systems…

Embedded Real-Time Systems– Execute on simple hardware, e.g. mobile phone,

vcr, microwave oven

Distributed Systems– Synchronize communication, ensure data

integrity, security– CORBA, DOM/DCOM

Page 16: 1 Object Oriented Analysis and Design with UML UNIT 2

16

Different Types of Systems…

System Software– Operating systems, DBMS, low level

operations on HW

Business Systems– Describes goals, resources, rules, actual work in

a business process

Page 17: 1 Object Oriented Analysis and Design with UML UNIT 2

17

Even more : UML is described in UML

Different Types of Systems.

Combinations are possibleUML can be used to model all of these

systems

Page 18: 1 Object Oriented Analysis and Design with UML UNIT 2

18

UML Diagrams...

Use-Case diagram Class diagram Object diagram State diagram Sequence diagram

Collaboration diagram Activity diagram Component diagram Deployment diagram

Page 19: 1 Object Oriented Analysis and Design with UML UNIT 2

19

Use-Case Diagram

Page 20: 1 Object Oriented Analysis and Design with UML UNIT 2

20

Class Diagram

Page 21: 1 Object Oriented Analysis and Design with UML UNIT 2

21

Object Diagram

Page 22: 1 Object Oriented Analysis and Design with UML UNIT 2

22

State Diagram

Page 23: 1 Object Oriented Analysis and Design with UML UNIT 2

23

Sequence Diagram

Page 24: 1 Object Oriented Analysis and Design with UML UNIT 2

24

Collaboration Diagram

Page 25: 1 Object Oriented Analysis and Design with UML UNIT 2

25

Activity Diagram

Page 26: 1 Object Oriented Analysis and Design with UML UNIT 2

26

Component Diagram

Page 27: 1 Object Oriented Analysis and Design with UML UNIT 2

27

Deployment Diagram

Page 28: 1 Object Oriented Analysis and Design with UML UNIT 2

28

UML Views…

Each view is a projection of the complete system

Each view highlights particular aspects of the system

Views are described by a number of diagrams

No strict separation, so a diagram can be part of more than one view

Page 29: 1 Object Oriented Analysis and Design with UML UNIT 2

29

UML Views…

Use CaseView

DeploymentView

ConcurrencyView

ComponentView

LogicalView

Page 30: 1 Object Oriented Analysis and Design with UML UNIT 2

30

Use Case View…

Shows the functionality of the system as perceived by external actors

Actors can be users or other systems Described by use case and activity diagrams The central view which drives the development

and planning of other views Used by customers, designers, developers, testers

Page 31: 1 Object Oriented Analysis and Design with UML UNIT 2

31

Logical View…

Shows how the functionality of the system is designed / provided

Uses class and object diagrams to represent the static structure

Uses state, sequence, collaboration, and activity diagrams for dynamic behaviour

Used by designers and developers

Page 32: 1 Object Oriented Analysis and Design with UML UNIT 2

32

Component View…

Shows the organization of the code components and their dependencies

Described by component diagrams Used by developers

Page 33: 1 Object Oriented Analysis and Design with UML UNIT 2

33

Concurrency View…

Addresses the problems with communication and synchronization for a concurrent system

Described by state, sequence, collaboration, activity, deployment, and component diagrams

Used by developers and system integrators

Page 34: 1 Object Oriented Analysis and Design with UML UNIT 2

34

Deployment View.

Shows the deployment of the system into the physical architecture with computers and devices

Represented by the deployment diagram Used by developers, system integrators, and

testers

Page 35: 1 Object Oriented Analysis and Design with UML UNIT 2

35

A Process for Making Models...

Brainstorming Sketching

Organizing

Specifying

Use informal tools:- Whiteboard- Post-it notes

Organize the informal sketch ina tool to producea formal diagram

Specify the detailsof the diagram, as more and more is learned (iterative)

Input Knowledge, Experience, Problem Description, Goals, …

Page 36: 1 Object Oriented Analysis and Design with UML UNIT 2

36

A Process for Making Models.

Check the diagram ,verify/validateagainst req.

Make a prototypeand test…

Evaluate resultgo back andcorrect anydeficiencies

Verifying

Prototyped &Tested

Evaluate

Integrating Validating

Page 37: 1 Object Oriented Analysis and Design with UML UNIT 2

37

Unit 2 : Outline

The History of the UML General overview of the UML Use Case Diagram Class Diagram

Page 38: 1 Object Oriented Analysis and Design with UML UNIT 2

38

Primary Purpose

Decide and describe functional requirements– Resulting in an agreement and planning

Clear description of what the system should do– Looks at the system as a black box

Used throughout entire development– Communication of requirements to all

developers– Basis for design, system tests, verification

Page 39: 1 Object Oriented Analysis and Design with UML UNIT 2

39

Who has Interest in Use Cases?

Customers and end users– Specification of the functionality of the system and

how it can and will be used

Developers– Understanding of what the system should do and a

foundation for future work

System integrators and testers– Basis to check wether the system performs as required

Anyone involved in activities of the system

Very Informal

Formal

Very Formal

Page 40: 1 Object Oriented Analysis and Design with UML UNIT 2

40

Parts of a Use Case Diagram...

The system The actors

The use cases

Insurance system

Customer

Customer statistics

Page 41: 1 Object Oriented Analysis and Design with UML UNIT 2

41

Parts of a Use Case Diagram...

The system– Could be any system, not just SW systems– Define clear and precise boundaries

• Don’t be too ambitious - think small !• Identify the basic functionality and concentrate on

defining a stable and well-defined system architecture• More functionality can always be added in future

versions

– Compile a catalog of central concepts or entities and describe them !

Page 42: 1 Object Oriented Analysis and Design with UML UNIT 2

42

Parts of a Use Case Diagram...

The actors– Who or what uses the system

• Represents a role, not an individual user of the system !

– Communicates with the system by sending and receiving messages

– Actors are in control and initiate actions– Actors can be ranked :

• Primary and secondary actors

Page 43: 1 Object Oriented Analysis and Design with UML UNIT 2

43

Parts of a Use Case Diagram.

Use cases– A set of sequences of actions a system performs

• A textual description !

– Always initiated by an actor

– Always delivers an observable result of value to an actor

• ”receive a bill for service” ?

– A use case is connected to an actor through associations• Normally undirected one-to-one relations

Page 44: 1 Object Oriented Analysis and Design with UML UNIT 2

44

Steps for Building a Use Case Model

Define the boundaries of the system– Divide into subsystems

Find the actors and use cases– For big systems define the actors first

Define the relationships between the use cases– extends

– uses

Validate and verify the model– Highly interactive with the end users !

– Should include discussions

Page 45: 1 Object Oriented Analysis and Design with UML UNIT 2

45

How to Find Actors ?

Who will use the main functionality of the system? Who will need support from the system to do their

daily tasks? Who needs to maintain, administrate and keep the

system working? Which HW devices does the system need to handle? With which other systems does the system interact? Who or what has an interest in the produced results?

Page 46: 1 Object Oriented Analysis and Design with UML UNIT 2

46

Describing a Use Case…

Use cases are goal oriented !– What is it trying to achieve– Which functions does the actor require, what

does he need to do?– Which actor initiates the use case and in which

situations?– Which messages or events are necessary

Page 47: 1 Object Oriented Analysis and Design with UML UNIT 2

47

Describing a Use Case.

– What is the flow of messages between actors and the use case?

• Depends on conditions and exceptions– Be cautious : don’t be too detailed

– Specific exceptions can be clarified by scenarios

– Which entities are modified and/or used?– When is the use case considered to be finished

and what kind of value is delivered to the actor?

Page 48: 1 Object Oriented Analysis and Design with UML UNIT 2

48

Relationships...

Extends relationship– The extension may use parts of the

generalization– Difficult to define the

reused parts• Use cases are written in

natural language !

Signing Insurance Policy

Client under 21

«extends»

Page 49: 1 Object Oriented Analysis and Design with UML UNIT 2

49

Relationships...

Uses relationship– The entire use case is used

Signing Insurance Policy

Signing Car Insurance Signing Life Insurance

«uses» «uses»

Page 50: 1 Object Oriented Analysis and Design with UML UNIT 2

50

Relationships.

Grouping into a package– Use cases with similar or related functionality

can be grouped (cfr Java packages)

Page 51: 1 Object Oriented Analysis and Design with UML UNIT 2

51

Example : Recycling Machine...

Customer Operator

Return Item

Print Daily Report

Change Item Data

Page 52: 1 Object Oriented Analysis and Design with UML UNIT 2

52

When the customer returns a deposit item, it is measured by the system.

IF accepted, the customer’s total is incremented and .... IF the item is rejected ...

The following information is printed on a receipt form: name, number returned, ...

Example : Recycling Machine...

Return Item

Page 53: 1 Object Oriented Analysis and Design with UML UNIT 2

53

Example : Recycling Machine.

Return Item

Item stuck

extends

When an item gets stuck, the alarm is activated to call the operator.

When the Operator has removed the stuck item he resets the alarm and the Customer can continu to return items.

Page 54: 1 Object Oriented Analysis and Design with UML UNIT 2

54

Summary

A technique to describe the functional requirements of a system

Described in terms of external actors, use cases and the system modeled

Use cases can be related to each other : extended, used, grouped.

Page 55: 1 Object Oriented Analysis and Design with UML UNIT 2

55

Unit 2 : Outline

The History of the UML General overview of the UML Use Case Diagram Class Diagram

Page 56: 1 Object Oriented Analysis and Design with UML UNIT 2

56

Class Diagrams

Perspectives– Conceptual

• No relation with the software

– Specification• Interfaces of the software

– Implementation• The real classes

Page 57: 1 Object Oriented Analysis and Design with UML UNIT 2

57

Class Diagrams

Static model type– A view of the system in terms of classes and

relationships (associations – subtypes - …) Classes not only describe information but

also behaviour ! Description of object types .

Attributes and behaviour of a type of objects– All objects are instances of a certain class

Page 58: 1 Object Oriented Analysis and Design with UML UNIT 2

58

Examples of Classes…

In business and information systems :– Customer– Agreement– Invoice– Debt– Asset– Quotation

Page 59: 1 Object Oriented Analysis and Design with UML UNIT 2

59

Examples of Classes…

In technical systems– Sensor– Display– I/O card– Engine– Button– Control class

Page 60: 1 Object Oriented Analysis and Design with UML UNIT 2

60

Examples of Classes.

In system software :– File

– Executable program

– Device

– Icon

– Window

– Scrollbar

Actually everything that has certain properties and behaviour

Page 61: 1 Object Oriented Analysis and Design with UML UNIT 2

61

A Class in UML…

A rectangle divided into 3 compartments :– name, attributes, operations

Name

Attributes

Operations

Page 62: 1 Object Oriented Analysis and Design with UML UNIT 2

62

A Class in UML…

The name compartment– Starts with an uppercase– Boldface– Most of the time a noun

Page 63: 1 Object Oriented Analysis and Design with UML UNIT 2

63

A Class in UML…

The attributes compartment– Starts with a lowercase– Has a type e.g. String, Integer, …– Has a visibility (language depended)

• public (+), private (-), protected (#)

– Default values can be specified– Allowed values can be specified ({...})– Class scope is possible (underlined)

Page 64: 1 Object Oriented Analysis and Design with UML UNIT 2

64

A Class in UML…

Invoice

+ amount : Real+ date : Date = Current date+ customer : String+ specification : String- administrator : String = “Unspecified”- number of invoices : Integer+ status : Status = unpaid { unpaid, paid }

Page 65: 1 Object Oriented Analysis and Design with UML UNIT 2

65

A Class in UML…

Public class Invoice{ public double amount; public Date date = new Date(); public String customer; static private int number_of_invoices = 0; // Constructor, called every time an object is created

public Invoice() { // Other initialization number_of_invoices++; //increment the class attribute }

// Other methods go here};

Invoice

+ amount : Real+ date : Date = Current date+ customer : String- number of invoices : Integer = 0

Page 66: 1 Object Oriented Analysis and Design with UML UNIT 2

66

A Class in UML…

The operation compartment :– Contains the signature of the operation

• a return type

• a name

• zero or more parameters

– Has a visibility• public (+), private (-), protected (#)

Page 67: 1 Object Oriented Analysis and Design with UML UNIT 2

67

A Class in UML…

size : Sizepos : Position

+ draw ()+ scaleFigure (percent : Integer = 25)+ returnPos () : Position

Figure

Page 68: 1 Object Oriented Analysis and Design with UML UNIT 2

68

A Class in UML.

Public class Figure

{

private int x = 0;

private int y = 0;

public void draw()

{

// Java code for drawing the figure

}

};

- x : Integer = 0- y : Integer = 0

+ draw ()

Figure

Page 69: 1 Object Oriented Analysis and Design with UML UNIT 2

69

Finding Classes

Do we have information that should be stored or analysed?

Do we have an external system? Do we have any patterns, class libraries,

components from earlier projects? Are there devices that the system should handle? Do we have organizational parts? Which roles do the actors play? Information comes from requirements !

Page 70: 1 Object Oriented Analysis and Design with UML UNIT 2

70

Relationships Between Classes

An association is a connection between classes A generalization is a relationship between a more

general and a more specific element A dependency is a relationship between elements,

one independent another dependent A refinement is a relationship between two

descriptions of the same thing but at different levels of abstraction

Page 71: 1 Object Oriented Analysis and Design with UML UNIT 2

71

Association Relationship…

Normally bidirectional Could contain multiplicity

– a range that tells us how many objects are linked

Association

Association name Association direction

UsesAuthor Computer

Page 72: 1 Object Oriented Analysis and Design with UML UNIT 2

72

Association Relationship…

A Person Owns 0 or many CarsA Car is Owned by 1 or many Persons

OwnsCarPerson

Owned by

1..* 0..*

Multiplicities

Page 73: 1 Object Oriented Analysis and Design with UML UNIT 2

73

Associations

Insurancecontract

Insurancepolicy

Insurancecompany

0..*1

has

refers to

0..*

1..*

refers to

Customer

0..1

hasexp

ressed an

is expressed

in an

Page 74: 1 Object Oriented Analysis and Design with UML UNIT 2

74

Recursive Associations

Connecting a class to itself

Node

Connects

*

*

Page 75: 1 Object Oriented Analysis and Design with UML UNIT 2

75

Roles in Associations

Specifies the contextof a class and its objects.

Role names arepart of the association not of the class

wife

Insurancecontract

Insurancepolicy

Insurancecompany

0..*1

ha

s

refers to

0..*

1..*

refe

rs to

Person

0..1

has

ex

pre

ss

ed a

n

is ex

pre

sse

d in

an

married to

husband

policyholder

Page 76: 1 Object Oriented Analysis and Design with UML UNIT 2

76

Qualified Associations

Specifies how a certain object at the many end is identified (+/- a key)

A Canvas contains many Figures which are identified by a figure id

Canvas figure id*

Figure

Page 77: 1 Object Oriented Analysis and Design with UML UNIT 2

77

‘OR’ Associations

In some models not all combinations are valid

An Insurance contract

belongs to a Person OR a Company

Insurancecompany

Insurancecontract

Person

0..*

1..*

Company

0..*

1..*

{or}

Page 78: 1 Object Oriented Analysis and Design with UML UNIT 2

78

Ordered Association

Insurancecontract

Customer

0..*

1..*

{ordered}

Page 79: 1 Object Oriented Analysis and Design with UML UNIT 2

79

Association Classes

The class Queue is needed for the association

Elevator

Queue

Elevatorcontrol

Button

*

4

Page 80: 1 Object Oriented Analysis and Design with UML UNIT 2

80

Ternary Associations

Insurancecompany

Insurancecontract

Person

0..*

1..*

Insurance policy

0..1

policyholder

0..*1

insurer

Page 81: 1 Object Oriented Analysis and Design with UML UNIT 2

81

Aggregation

A part-off association What is the difference with an association ? Only use it when it is clear why you use it !

NavyContains

* Warship

Page 82: 1 Object Oriented Analysis and Design with UML UNIT 2

82

Composition

Stronger variety of aggregation The parts can only exist if the whole exists

Notation (1/3)

* Text

Window

Listbox

Button

Menu*

*

*

Page 83: 1 Object Oriented Analysis and Design with UML UNIT 2

83

Composition Aggregation…

Notation (2/3)* Text

Window

Listbox

Button

Menu*

*

*

Contains

Page 84: 1 Object Oriented Analysis and Design with UML UNIT 2

84

Composition Aggregation.

Notation (3/3)

Window

Text

Listbox

Button

Menu

*

*

*

*

Page 85: 1 Object Oriented Analysis and Design with UML UNIT 2

85

Generalization…

Inheritance, ‘is-a’ relationship The more specific may be used where the

more general is allowed Private vs. protected

Remember :Using Inheritance

for code reuse, or just because it

looks nice is adangerous practice !

Boat TruckCar

Vehicle

Page 86: 1 Object Oriented Analysis and Design with UML UNIT 2

86

Generalization.

Abstract classes & Polymorphism

Facilitated through

Dynamic Binding

Page 87: 1 Object Oriented Analysis and Design with UML UNIT 2

87

General Example

Cfr. Composite

Design Pattern

Page 88: 1 Object Oriented Analysis and Design with UML UNIT 2

88

Dependency Relationship

Class A depends on Class B

(important to know for maintainability)

Class BClass A«friend»

Page 89: 1 Object Oriented Analysis and Design with UML UNIT 2

89

Refinement Relationship

A Design Class is a refinement of an Analysis Class

(important to know for abstraction levels)

Design classAnalysis class

Page 90: 1 Object Oriented Analysis and Design with UML UNIT 2

90

Extensibility of UML... Stereotypes

– Allows to define a new kind of model element based on an existing one

– Basically adds extra semantics– There are predefined stereotypes in UML

• simplicity !

Stereotype name Stereotype icon

Customer

Customer<<Actor>>Customer

Page 91: 1 Object Oriented Analysis and Design with UML UNIT 2

91

Extensibility of UML (2)

Tagged values– Name-value pairs of information– Hold additional information about elements

Constraints– Restrictions that limit the usage of an element

or the semantics of an element