chapter 2, modeling with uml g - computer science | …fiech/teaching/comp_6905/downloads/… ·...

67
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 2, Modeling with UML

Upload: truongnhu

Post on 19-Apr-2018

226 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Usin

g U

ML,

Pat

tern

s, an

d Ja

va

Obj

ect-O

rien

ted

Softw

are

Engi

neer

ing Chapter 2,

Modeling with UML

Page 2: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 2!

Dealing with Complexity

•  Three ways to deal with complexity •  Abstraction and Modeling •  Decomposition •  Hierarchy

•  Introduction into the UML notation •  First pass on:

•  Use case diagrams •  Class diagrams •  Sequence diagrams •  Statechart diagrams •  Activity diagrams

Page 3: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 3!

What is the problem with this Drawing?

Page 4: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 4!

Abstraction •  Complex systems are hard to understand

•  The 7 +- 2 phenomena •  Our short term memory cannot store more than 7+-2

pieces at the same time -> limitation of the brain •  My Phone Number: +17098648632

Page 5: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 5!

Abstraction

•  Chunking: •  Group collection of objects to reduce complexity •  4 chunks:

• Country-code, city-code, MUN-code, Office-Part

•  Complex systems are hard to understand •  The 7 +- 2 phenomena

•  Our short term memory cannot store more than 7+-2 pieces at the same time -> limitation of the brain

•  My Phone Number: +17098648632

Page 6: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 6!

Abstraction

MUN Phone Number!

Country-Code! City-Code! MUN-code! Office-Part!

•  Chunking: •  Group collection of objects to reduce complexity •  State-code, city-code, MUN-code, Office-Part

•  Complex systems are hard to understand •  The 7 +- 2 phenomena

•  Our short term memory cannot store more than 7+-2 pieces at the same time -> limitation of the brain

•  My Phone Number: +17098648632

Page 7: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 7!

Abstraction

•  Abstraction allows us to ignore unessential details •  Two definitions for abstraction:

•  Abstraction is a thought process where ideas are distanced from objects

•  Abstraction as activity •  Abstraction is the resulting idea of a thought process

where an idea has been distanced from an object •  Abstraction as entity

•  Ideas can be expressed by models

Page 8: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 8!

Model

•  A model is an abstraction of a system

•  A system that no longer exists •  An existing system •  A future system to be built.

Page 9: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 9!

We use Models to describe Software Systems

•  Object model: What is the structure of the system?

•  Functional model: What are the functions of the system?

•  Dynamic model: How does the system react to external events?

•  System Model: Object model + functional model + dynamic model

Page 10: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 10!

Decomposition

•  A technique used to master complexity (“divide and conquer”)

•  Two major types of decomposition •  Functional decomposition •  Object-oriented decomposition

•  Functional decomposition •  The system is decomposed into modules •  Each module is a major function in the

application domain •  Modules can be decomposed into smaller

modules.

Page 11: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 11!

Decomposition (cont’d)

•  Object-oriented decomposition •  The system is decomposed into classes (“objects”) •  Each class is a major entity in the application

domain •  Classes can be decomposed into smaller classes

•  Object-oriented vs. functional decomposition

Which decomposition is the right one?

Page 12: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 12!

Functional Decomposition

Top Level functions!

Level 1 functions!

Level 2 functions!

Machine instructions!

System !Function!

Load R10! Add R1, R10!

Read Input! Transform! Produce!Output!

Transform! Produce!Output!Read Input!

Page 13: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 13!

Functional Decomposition

•  The functionality is spread all over the system •  Maintainer must understand the whole system to

make a single change to the system •  Consequence:

•  Source code is hard to understand •  Source code is complex and impossible to maintain •  User interface is often awkward and non-intuitive.

Page 14: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 14!

Autoshape!

Functional Decomposition: Autoshape

Draw!Rectangle!

Draw!Oval!

Draw!Circle!

Change! Draw!

Change!Rectangle!

Change!Oval!

Change!Circle!

Page 15: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 15!

Object-oriented decomposition – What is This?

Neck

Glove

Coat Pocket

Cave

Ellbow

An Eskimo!!

Page 16: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 16!

Object-oriented decomposition – What is This?

Nose Eye

Ear

Chin Mouth

Hair

A Face!

Page 17: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 17!

Object-oriented decomposition – What is This?

Nose Eye

Ear

Chin Mouth

Hair

Ellbow!Neck

Glove

Coat Pocket

Cave

A Face! An Eskimo!

Page 18: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 18!

Class Identification

•  Basic assumptions: •  We can find the classes for a new software

system: Greenfield Engineering •  We can identify the classes in an existing

system: Reengineering •  We can create a class-based interface to an

existing system: Interface Engineering

Page 19: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 19!

Class Identification (cont’d)

•  Why can we do this? •  Philosophy, science, experimental evidence

•  What are the limitations? •  Depending on the purpose of the system,

different objects might be found

•  Crucial Identify the purpose of a system

Page 20: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 20!

Hierarchy

•  So far we got abstractions •  This leads us to classes and objects •  “Chunks”

•  Another way to deal with complexity is to provide relationships between these chunks

•  One of the most important relationships is hierarchy

•  2 special hierarchies •  "Part-of" hierarchy •  "Is-kind-of" hierarchy

Page 21: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 21!

I/O Devices! CPU! Memory!

Part-of Hierarchy (Aggregation)

Computer!

Cache! ALU! Program! Counter!

Page 22: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 22!

Is-Kind-of Hierarchy (Taxonomy)

Cell!

Muscle Cell! Blood Cell! Nerve Cell!

Striate! Smooth! Red! White! Cortical! Pyramidal!

Page 23: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 23!

Where are we now?

•  Three ways to deal with complexity: •  Abstraction, Decomposition, Hierarchy

•  Object-oriented decomposition is good •  Unfortunately, depending on the purpose of the

system, different objects can be found

•  How can we do it right? •  Start with a description of the functionality of a system •  Then proceed to a description of its structure

•  Ordering of development activities •  Software lifecycle

Page 24: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 24!

Concepts and Phenomena

•  Phenomenon •  An object in the world of a domain as you perceive it

•  Examples: This lecture at 9:35, my black watch

•  Concept •  Describes the common properties of phenomena

•  Example: All lectures on software engineering •  Example: All black watches

•  A Concept is a 3-tuple: •  Name: The name distinguishes the concept from other

concepts •  Purpose: Properties that determine if a phenomenon is

a member of a concept •  Members: The set of phenomena which are part of the

concept.

Page 25: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 25!

Definition Abstraction: •  Classification of phenomena into concepts

Definition Modeling: •  Development of abstractions to answer specific questions

about a set of phenomena while ignoring irrelevant details.

Members Name

Watch"

Purpose

A device that"measures time."

Concepts, Phenomena, Abstraction and Modeling

Page 26: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 26!

Abstract Data Types & Classes

•  Abstract data type •  A type whose implementation is

hidden from the rest of the system •  Class:

•  An abstraction in the context of object-oriented languages

•  A class encapsulates state and behavior

•  Example: Watch

Watch!time!date!SetDate(d)!

CalculatorWatch!

EnterCalcMode()!InputNumber(n)!

calculatorState!Unlike abstract data types, subclasses can be defined in terms of other classes using inheritance

State!

Behavior!

Inheritance!

Subclass!•  Example: CalculatorWatch

Superclass!

Page 27: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 27!

Systems

•  A system is an organized set of communicating parts •  Natural system: A system whose ultimate purpose is not

known •  Engineered system: A system which is designed and built by

engineers for a specific purpose

•  The parts of the system can be considered as systems again

•  In this case we call them subsystems

Examples of engineered systems: • Airplane, watch, GPS Examples of subsystems: • Jet engine, battery, satellite.

Examples of natural systems: • Universe, earth, ocean

Page 28: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 28!

Systems, Models and Views

• A model is an abstraction describing a system or a subsystem

System: Airplane

Models: Flight simulator Scale model

Views: Blueprint of the airplane components Electrical wiring diagram, Fuel system Sound wave created by airplane

• A view depicts selected aspects of a model

•  A notation is a set of graphical or textual rules for depicting models and views:

•  formal notations, “napkin designs”

Page 29: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 29!

Systems, Models and Views

System" View"*"Model"*"

Depicted by"Described by"

Airplane: System"

Scale Model:Model" Flight Simulator:Model"

Fuel System: View"

Electrical Wiring: View"

Blueprints: View"

(UML Notation) Class Diagram!

Object Diagram!

Page 30: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 30!

Application vs Solution Domain

•  Application Domain (Analysis): •  The environment in which the system is operating

•  Solution Domain (Design, Implementation): •  The technologies used to build the system

•  Both domains contain abstractions that we can use for the construction of the system model.

Page 31: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 31!

Object-oriented Modeling

Application Domain "(Phenomena)!

Solution Domain "(Phenomena)"

System Model (Concepts)! System Model (Concepts)"

Aircraft" TrafficController"

FlightPlan"Airport"

MapDisplay"

FlightPlanDatabase"

Summary"Display"

TrafficControl"

TrafficControl"

UML !Package!

(Analysis)! (Design)!

Page 32: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 32!

What is UML?

•  UML (Unified Modeling Language) •  Nonproprietary standard for modeling software systems, OMG •  Convergence of notations used in object-oriented methods

•  OMT (James Rumbaugh and collegues) •  Booch (Grady Booch) •  OOSE (Ivar Jacobson)

•  Current Version: UML 2.5 •  Information at the OMG portal http://www.uml.org/

•  Commercial tools: Rational (IBM),Together (Borland), Visual Architect (business processes, BCD)

•  Open Source tools: ArgoUML, StarUML, Umbrello •  Commercial and Opensource: PoseidonUML (Gentleware)

Page 33: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 33!

UML: First Pass

•  You can model 80% of most problems by using about 20 % UML

•  We teach you those 20%

•  80-20 rule: Pareto principle •  http://www.ephorie.de/hindle_pareto-prinzip.htm

Page 34: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 34!

UML First Pass

•  Use case diagrams •  Describe the functional behavior of the system as seen

by the user

•  Class diagrams •  Describe the static structure of the system: Objects,

attributes, associations

•  Sequence diagrams •  Describe the dynamic behavior between objects of the

system

•  Statechart diagrams •  Describe the dynamic behavior of an individual object

•  Activity diagrams •  Describe the dynamic behavior of a system, in

particular the workflow.

Page 35: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 35!

UML Core Conventions

•  All UML Diagrams denote graphs of nodes and edges

•  Nodes are entities and drawn as rectangles or ovals •  Rectangles denote classes or instances •  Ovals denote functions

•  Names of Classes are not underlined •  SimpleWatch •  Firefighter

•  Names of Instances are underlined •  myWatch:SimpleWatch!•  Joe:Firefighter!

•  An edge between two nodes denotes a relationship between the corresponding entities

Page 36: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 36!

UML first pass: Use case diagrams

Use case diagrams represent the functionality of the system"from user’s point of view"

Actor."

Use Case"

System boundary"

Classifier"

Page 37: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 37!

UML first pass: Class diagrams

Class"Association"

Multiplicity"

Class diagrams represent the structure of the system"

2 1 1

1 1

1 1

2

SimpleWatch

Display Battery Time PushButton

Page 38: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 38!

UML first pass: Class diagrams

1"2"

push() release()"

1"

1"

blinkIdx"blinkSeconds()"blinkMinutes()"blinkHours()"stopBlinking()"referesh()"

LCDDisplay" Battery"Load"

1"

2"

1"

Time"Now"

1"

Watch"

Operations"

state"PushButton"

Attribute"

Class diagrams represent the structure of the system"

Class"Association"

Multiplicity"

Page 39: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 39!

Message"

UML first pass: Sequence diagram

:Time" :Watch":WatchUser"

Object"

Activation"

Sequence diagrams represent the behavior of a system "as messages (“interactions”) between different objects"

Actor"

pressButton1()"

Lifeline"

blinkHours()"

pressButton2()"incrementMinutes()"

:LCDDisplay"

pressButton1and2()"commitNewTime()"

stopBlinking()"

refresh()"

pressButton1()"blinkMinutes()"

Page 40: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 40!

UML first pass: Statechart diagrams

State"

Initial state"

Final state"

Transition"

Event"

Represent behavior of a single object with interesting dynamic behavior."

button1&2Pressed

button1Pressed

button2Pressed

button2Pressed

button2Pressed

button1Pressed

button1&2Pressed Increment Minutes

Increment Hours

Blink Hours

Blink Seconds

Blink Minutes

Increment Seconds

Stop Blinking

Page 41: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 41!

What should be done first? Coding or Modeling?

•  It all depends…. •  Forward Engineering

•  Creation of code from a model •  Start with modeling •  Greenfield projects

•  Reverse Engineering •  Creation of a model from existing code •  Interface or reengineering projects

•  Roundtrip Engineering •  Move constantly between forward and reverse

engineering •  Reengineering projects •  Useful when requirements, technology and schedule

are changing frequently.

Page 42: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 42!

UML Use Case Diagrams

An Actor represents a role, that is, a type of user of the system

Passenger"

PurchaseTicket"

Used during requirements elicitation and analysis to represent external behavior (“visible from the outside of the system”)

Use case model: The set of all use cases that completely describe the functionality of the system.

A use case represents a class of functionality provided by the system

Page 43: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 43!

Actors

•  An actor is a model for an external entity which interacts (communicates) with the system:

•  User •  External system (Another system) •  Physical environment (e.g. Weather)

•  An actor has a unique name and an optional description

•  Examples: •  Passenger: A person in the train •  GPS satellite: An external system that

provides the system with GPS coordinates.

Passenger"

Name!

Optional !Description!

Page 44: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 44!

Use Case • A use case represents a class of

functionality provided by the system

• Use cases can be described textually, with a focus on the event flow between actor and system

• The textual use case description consists of 6 parts: 1. Unique name 2.  Participating actors 3.  Entry conditions 4.  Exit conditions 5.  Flow of events 6.  Special requirements.

PurchaseTicket"

Page 45: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 45!

Textual Use Case Description Example

1. Name: Purchase ticket

2. Participating actor: Passenger

3. Entry condition: •  Passenger stands in front

of ticket distributor •  Passenger has sufficient

money to purchase ticket

4. Exit condition: •  Passenger has ticket

5. Flow of events: 1. Passenger selects the

number of zones to be traveled

2. Ticket Distributor displays the amount due

3. Passenger inserts money, at least the amount due

4. Ticket Distributor returns change

5. Ticket Distributor issues ticket

6. Special requirements: None.

Passenger" PurchaseTicket"

Page 46: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 46!

Uses Cases can be related

•  Extends Relationship •  To represent seldom invoked use cases or exceptional

functionality

•  Includes Relationship •  To represent functional behavior common to more than

one use case.

Page 47: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 47!

The <<extends>> Relationship •  <<extends>> relationships

model exceptional or seldom invoked cases

•  The exceptional event flows are factored out of the main event flow for clarity

•  The direction of an <<extends>> relationship is to the extended use case

•  Use cases representing exceptional flows can extend more than one use case.

Passenger"

PurchaseTicket"

TimeOut"

<<extends>>"

NoChange"

<<extends>>"OutOfOrder"

<<extends>>"

Cancel"

<<extends>>"

Page 48: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 48!

The <<includes>> Relationship •  <<includes>> relationship

represents common functionality needed in more than one use case

•  <<includes>> behavior is factored out for reuse, not because it is an exception

•  The direction of a <<includes>> relationship is to the using use case (unlike the direction of the <<extends>> relationship).

Passenger"

PurchaseSingleTicket"

PurchaseMultiCard"

<<includes>>"

CollectMoney"

<<includes>>"

NoChange"

<<extends>>"

Cancel"

<<extends>>"

Cancel"

<<extends>>"

Page 49: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 49!

Class Diagrams

•  Class diagrams represent the structure of the system

•  Used •  during requirements analysis to model application

domain concepts •  during system design to model subsystems •  during object design to specify the detailed behavior

and attributes of classes.

Table zone2price"Enumeration getZones()"Price getPrice(Zone)"

TarifSchedule"

*" *"

Trip"zone:Zone"

Price: Price"

Page 50: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 50!

Classes

•  A class represents a concept •  A class encapsulates state (attributes) and behavior

(operations)

Table zone2price"Enumeration getZones()"Price getPrice(Zone)"

TarifSchedule"

zone2price"getZones()"getPrice()"

TarifSchedule"

Name"

Attributes"

Operations"

Signature"

TarifSchedule"

The class name is the only mandatory information

Each attribute has a type Each operation has a signature

Type"

Page 51: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 51!

Instances

•  An instance represents a phenomenon •  The attributes are represented with their values •  The name of an instance is underlined •  The name can contain only the class name of the instance

(anonymous instance)

zone2price = {"{‘1’, 0.20}, {‘2’, 0.40},"{‘3’, 0.60}}"

tarif2006:TarifSchedule"zone2price = {"{‘1’, 0.20}, {‘2’, 0.40},"{‘3’, 0.60}}"

:TarifSchedule"

Page 52: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 52!

Actor vs Class vs Object

•  Actor •  An entity outside the system to be modeled,

interacting with the system (“Passenger”)

•  Class •  An abstraction modeling an entity in the application or

solution domain •  The class is part of the system model (“User”, “Ticket

distributor”, “Server”)

•  Object •  A specific instance of a class (“Joe, the passenger who

is purchasing a ticket from the ticket distributor”).

Page 53: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 53!

Associations

Associations denote relationships between classes

Price Zone"

Enumeration getZones()"Price getPrice(Zone)"

TarifSchedule" TripLeg"

*" *"

The multiplicity of an association end denotes how many objects the instance of a class can legitimately reference.

Page 54: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 54!

1-to-1 and 1-to-many Associations

1-to-1 association

1-to-many association

Polygon!

draw()"

Point!

x: Integer"

y: Integer"

*!

Country!

name:String"

City!

name:String"

1!1!

Page 55: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 55!

Many-to-Many Associations

StockExchange

Company

tickerSymbol *!*!

Page 56: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 56!

Aggregation •  An aggregation is a special case of association denoting

a “consists-of” hierarchy •  The aggregate is the parent class,

the components are the children classes

Exhaust system!

Muffler!diameter"

Tailpipe!diameter"

1" 0..2"

TicketMachine"

ZoneButton"3"

A solid diamond denotes composition: A strong form of aggregation where the life time of the component instances is controlled by the aggregate. That is, the parts don’t exist on their won (“the whole controls/destroys the parts”)

Page 57: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 57!

Inheritance

•  Inheritance is another special case of an association denoting a “kind-of” hierarchy

•  Inheritance simplifies the analysis model by introducing a taxonomy

•  The children classes inherit the attributes and operations of the parent class.

Button!

ZoneButton"CancelButton"

Page 58: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 58!

Packages

•  Packages help you to organize UML models to increase their readability

•  We can use the UML package mechanism to organize classes into subsystems

•  Any complex system can be decomposed into subsystems, where each subsystem is modeled as a package.

Account"

Customer"Bank"

Page 59: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 59!

Sequence Diagrams

•  Used during analysis •  To refine use case descriptions •  to find additional objects

(“participating objects”) •  Used during system design

•  to refine subsystem interfaces •  Instances are represented by

rectangles. Actors by sticky figures

•  Lifelines are represented by dashed lines

•  Messages are represented by arrows

•  Activations are represented by narrow rectangles.

selectZone()"

pickupChange()"

pickUpTicket()"

insertCoins()"

TicketMachine"Passenger"

Focus on !Controlflow!

Page 60: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 60!

Sequence Diagrams can also model the Flow of Data

•  The source of an arrow indicates the activation which sent the message

•  Horizontal dashed arrows indicate data flow, for example return results from a message

Passenger"selectZone()"

ZoneButton" TarifSchedule" Display"

lookupPrice(selection)"

displayPrice(price)"price"

Dataflow"…continued on next slide..."

Page 61: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 61!

Sequence Diagrams: Iteration & Condition

•  Iteration is denoted by a * preceding the message name •  Condition is denoted by boolean expression in [ ] before

the message name

Passenger" ChangeProcessor"insertChange(coin)"

CoinIdentifier" Display" CoinDrop"

displayPrice(owedAmount)"

lookupCoin(coin)"price"

[owedAmount<0] returnChange(-owedAmount)"

Iteration"

Condition"

…continued on next slide...

…continued from previous slide..."

*!

Page 62: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 62!

Creation and destruction

•  Creation is denoted by a message arrow pointing to the object •  Destruction is denoted by an X mark at the end of the

destruction activation •  In garbage collection environments, destruction can be used to

denote the end of the useful life of an object.

Passenger" ChangeProcessor"

…continued from previous slide..."

Ticket"createTicket(selection)"

free()"

Creation of Ticket"

Destruction of Ticket"

print()"

Page 63: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 63!

Sequence Diagram Properties

•  UML sequence diagram represent behavior in terms of interactions

•  Useful to identify or find missing objects •  Time consuming to build, but worth the

investment •  Complement the class diagrams (which

represent structure).

Page 64: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 64!

Activity Diagrams

•  An activity diagram is a special case of a state chart diagram

•  The states are activities (“functions”) •  An activity diagram is useful to depict the

workflow in a system

HandleIncident

DocumentIncident

ArchiveIncident

Page 65: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 65!

Activity Diagrams allow to model Decisions

OpenIncident

NotifyPolice Chief

NotifyFire Chief

AllocateResources

[fire & highPriority]

[not fire & highPriority]

[lowPriority]

Decision"

Page 66: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 66!

Activity Diagrams can model Concurrency

•  Synchronization of multiple activities •  Splitting the flow of control into multiple threads

OpenIncident

AllocateResources

CoordinateResources

DocumentIncident

ArchiveIncident

Synchronization!Splitting!

Page 67: Chapter 2, Modeling with UML g - Computer Science | …fiech/teaching/comp_6905/downloads/… ·  · 2015-09-21Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering:

Bernd Bruegge & Allen H. Dutoit ! ! Object-Oriented Software Engineering: Using UML, Patterns, and Java 67!

Activity Diagrams: Grouping of Activities

•  Activities may be grouped into swimlanes to denote the object or subsystem that implements the activities.

Open!Incident!

Allocate!Resources!

Coordinate!Resources!

Document!Incident!

Archive!Incident!

Dispatcher!

FieldOfficer!