Modeling Concepts and Overview of the Unified Modeling Language (UML)

248
Modeling Concepts and Overview of the Unified Modeling Language (UML)

description

Modeling Concepts and Overview of the Unified Modeling Language (UML). Modeling Introduction. What is a model? - Model is a representation or simplification of reality - Abstraction allows us to focus on the essential aspects of a model - PowerPoint PPT Presentation

Transcript of Modeling Concepts and Overview of the Unified Modeling Language (UML)

Page 1: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Modeling Concepts and Overview of the Unified Modeling Language (UML)

Page 2: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Modeling Introduction

• What is a model?

- Model is a representation or simplification of reality- Abstraction allows us to focus on the essential aspects of a model- A good model is the crux of good software development

• Why model?

- A good model helps us to visualize, specify, construct, and document what we are building - Models helps us to view (and understand) the system under development from different perspectives- Models obtained through abstraction enable us to handle complexity in a disciplined manner

Page 3: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Modeling Introduction contd.....

- Models facilitate communication between the users, the developers, and other shareholders

• Principles of Modeling

- Choose the right model- Use different levels of abstraction- Models should be a reflection of reality- Different models, each representing different aspects (e.g., static vs dynamic features), are required to represent reality adequately

Page 4: Modeling Concepts and Overview of the Unified Modeling Language (UML)

UML Overview

What is the Unified Modeling Language (UML)? (Booch et al., 1999)

• The UML is a modeling language (it has a vocabulary and rules for using the vocabulary) that allows us to visualize, specify, construct, and document the artifacts of a software system

• For best results, the UML must be used in the context of a process that is use case driven, architecture-centric, iterative, and incremental

• It is expressive, yet easy to use

Page 5: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Conceptual Model of the UML

Conceptually, the UML consists of:

• Building Blocks ( things, relationships, and diagrams)

• Rules

• Mechanisms

Page 6: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Things in the UML

• Structural Things (interfaces, classes, use cases, collaborations, active classes, component, node)

• Behavioral Things (interactions and state machines)

• Grouping Things (packages)

• Annotational Things (notes)

Page 7: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Relationships in the UML

• Association

• Generalization

• Realization

• Dependency

Page 8: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Diagrams in the UML

• Use Case Diagram• Activity Diagram• Class Diagram• Object Diagram• Sequence Diagram• Collaboration Diagram• Statechart Diagram• Component Diagram• Deployment Diagram

Page 9: Modeling Concepts and Overview of the Unified Modeling Language (UML)

UML Rules

• A good (well-formed) model should conform to UML’s semantic rules

• Semantic rules exist for names, scope, visibility, integrity, execution

• Circumstances (such as the increasing complexity of a system under development) sometimes compel us to elide (hide details to simplify the view), leave out elements (incomplete model), or compromise the integrity of the model (inconsistent model)

Page 10: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Common Mechanisms in the UML

• Specifications

• Adornments

• Common division ( class/object, interface/implementation)

• Extensibility Mechanisms (Stereotypes, Tagged Values, Constraints)

Page 11: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Architecture

• System should be viewed from a number of perspectives

• Architecture deals with structural and behavioral aspects of a system, as well as with other concerns such as reuse, performance, scalability, functionality, constraints, trade-offs, and so forth

• Five interlocking views may be used to delineate an architecture:Use Case ViewDesign View (sometimes referred to as the Logical View)Process ViewImplementation ViewDeployment View

Page 12: Modeling Concepts and Overview of the Unified Modeling Language (UML)

The Process

• The UML should be used in the context of a process

• For best results, the process should be:Use Case DrivenArchitecture-CentricIterative and incremental

• Typical phases of a process are:Inception - make a business caseElaboration - product vision & architecture, requirements, project plan, risk evaluation, basis for testingConstruction - iteratively and incrementally build a product, test, refine designs, ensure consistency with requirements, acceptance criteria, etc., Transition - hand over the system to the end users, continually evaluate, improve, and enhance the system

Page 13: Modeling Concepts and Overview of the Unified Modeling Language (UML)

OO Concepts

Page 14: Modeling Concepts and Overview of the Unified Modeling Language (UML)

OO Concepts

• A class encapsulates data and procedures• A class is an abstraction that maps onto a real world abstraction• A class may be abstract or concrete

Page 15: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Example of a class

public class Account {private String accountNumber;private float balance;public Account(String aNumber){

accountNumber = aNumber;}public void withdraw(float money) { ...... }public void deposit(float money) {.....}}

Page 16: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Object

• An object is an instance of a class• It can be identified with some occurrence in the real world• Objects have identity, state, and behavior• Example:

Account myAccount = new Account(“1000”);myAccount is an object

Page 17: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Instance Versus Class Variables

• Instance variable: Each instance has its own value for that variable, e.g., each account instance has its own balance

• Class variable: It is a variable that is shared by all instances of the class, e.g., A minimum balance for an Account may be shared by all Account instances

Page 18: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Inheritance

• The properties of a superclass are acquired by the subclasses• The subclasses may override and/or extend the properties of the superclass• Example: In our example, Savings and Checking could be subclasses of

Account

Page 19: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Polymorphism and Dynamic Binding

• A client that deals with a class can also use the subclasses of that class• A polymorphic variable can refer to objects of different classes. Example:

Account c = new Checking(); // c.withdraw(200.00);c = new Savings(); // c.withdraw(500.00);

• A polymorphic function may take arguments of different types. Example:void f(Account anAccount) { .... } can be invoked with c as an argument as long c is an instance of Savings or Checking

Page 20: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Dynamic Binding

• Binding that occurs at compile time is called Static Binding• Run time binding is referred to as Dynamic Binding• Dynamic binding gives run time flexibility

Page 21: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Introduction to OO Analysis and Design

Page 22: Modeling Concepts and Overview of the Unified Modeling Language (UML)

OO Analysis

OO Analysis:•Functional Requirements definition of the system•Description of classes in the problem domain•High-level system components and their interactions•Interaction between classes

Page 23: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Source: The internet

Page 24: Modeling Concepts and Overview of the Unified Modeling Language (UML)

OO Design

•Transform analysis model into a feasible design•Define operations and other features•Define how these features are to be realized•Define organization of system in terms of building blocks

Page 25: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Why OO?

•Flexibility - reuse, extensibility•OO development is a relatively seamless process•Abstractions/classes can be mapped onto real-world concepts•OO makes it easier to deal with complexity•Lends itself to prototyping

Page 26: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Different Views of a System

•Functional ViewUse cases provide a static functional view while activity diagrams give a dynamic functional view

•Static Structural ViewClass and object diagrams

Page 27: Modeling Concepts and Overview of the Unified Modeling Language (UML)

•Behavioral (Dynamic Structural) ViewInteraction DiagramsState Machines

•Architectural ViewLogical (e.g., Package Diagrams), hardware (e.g., Deployment Diagrams), process, and implementation (e.g., Component Diagram) architectures

Page 28: Modeling Concepts and Overview of the Unified Modeling Language (UML)

What constitutes a flexible design?

•High CohesionClasses should represent a single abstraction and each method should fulfill a responsibility•Low CouplingDependencies/interactions between classes should be minimized•Behavior should be evenly distributed“Inquisitive’ control objects should be avoided•High modularity

Page 29: Modeling Concepts and Overview of the Unified Modeling Language (UML)

System Functional Models

•Functional model leads to design which in turn leads to implementation

•Functional requirements define the requirements of a system from an external perspective

Page 30: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Types of Requirements

• Functional - system does what is it supposed to do• Performance, e.g., response time• Robustness, e.g., exception handling• Compatibility with other systems, reusability, etc.,

Page 31: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Use Cases

•Use cases represent the typical interactions between users and the system•A use case is a coherent unit of functionality that satisfies some user-visible function, thus helping the user achieve a discrete goal•Use cases could be trivial or non-trivial, big or small

Page 32: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Use Case Identification

•Identify the actors•Determine the interactions between the actors and the system•What interactions are initiated by the actors?•What interactions are initiated by the system?

Page 33: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Use Case Identification

• What information should the system store? How is this information created, stored, updated, deleted, and queried?

• Are there any time-based activities performed by the system?• Are there any external events that affect the system?• Are there any activities performed when the internal state of the system

changes?

Page 34: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Actors

• Actors are external to the system• People (more specifically, roles of people), external systems that interface

with the system being designed, and devices are typically the actors of a system

• Actors may be primary or secondary (supporting)• Primary actors usually benefit from their interactions with the system

Page 35: Modeling Concepts and Overview of the Unified Modeling Language (UML)

PLACE ORDER

CANCEL ORDER

CANCEL ORDERITEM

RETURN ORDERITEM

CATALOG ORDER SYSTEM

CATALOG CUSTOMER

Page 36: Modeling Concepts and Overview of the Unified Modeling Language (UML)

USES and EXTENDS relationships

Cancel Order

<<uses>>

Cancel Order Item

The behavior “Cancel Order Item” is always included inthe “Cancel Order’ use case

Page 37: Modeling Concepts and Overview of the Unified Modeling Language (UML)

<<extends>> Relationship

Place Order Add Customer

<<extends>>

The use case “Place Order’ sometimes includes the behaviorof “Add Customer” (for example when “Place Order” attemptsto create an order for a customer who has not yet been added tothe system)

Page 38: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Use Case Specifications

• A textual description of the use case should be made• The description specifies how the use case carries out its functionality• The description usually includes a trigger (what starts the use case?), pre-

condition, flow of events, alternative flows, and post-conditions

Page 39: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Sample Use case Specification

Name: Cancel Order ItemTrigger: The use case starts when the telephone agent (for the customer) enters

“Cancel Order Item”Pre-condition: An order o exists for the given order numberMain flow of events:

1. Find all line items for the order o2. For each line item found

cancel line item end

Page 40: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Use case description continued...

3. Order is marked canceled and the use case endsAlternative paths

If any of the line items is “Not pending”, the order cannot be canceled, and the use case ends

Post-condition: The order has been marked canceled and saved

Page 41: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Activity Diagrams

•Use case presents a static view of system functionality•The sequence of use case execution, conditions under which an extension occurs, and temporal relationships are hard to divine from use case diagrams•An activity diagram flowcharts the workflow of activities and presents the steps in a use case•An activity diagram is therefore a dynamic representation os system functionality

Page 42: Modeling Concepts and Overview of the Unified Modeling Language (UML)

An activity in an activity diagram may be a task, another use case, or just a step being done in the use case

An activity

A B Activity B follows A

Start End

Page 43: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Activity Diagram notations

A B

C

[x == 5]

[x != 5]

You could also have nested decision points

Page 44: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Activity Diagrams notations

A

B

C

D

Synchronization Bar

Page 45: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 46: Modeling Concepts and Overview of the Unified Modeling Language (UML)

ENTER ORDER

AUTHORIZEFUNDS

ALLOCATEINVENORY

SHIP ORDER

[DENIED]

[COMMITTED]

[APPROVED]

ACTIVITY DIAGRAM FOR PLACING AN ORDER

Page 47: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 48: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 49: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 50: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Class Diagramming Notation

Page 51: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Class Diagrams

ASSOCIATION: relationships between instances of a classes, e.g., customer places order, employee works for company

•Each association has two roles•Each role has multiplicity

Customer Order

0..*1..1 0..*1..1Role A

Role B

Page 52: Modeling Concepts and Overview of the Unified Modeling Language (UML)

A B1

Only one B is associated with an A

A B1..*

One or more instances of B are associated with an A

A B

0 or 1 instance of B is associated with an A

0..1

A B*

An A is associated with 0 or more instances of B

Page 53: Modeling Concepts and Overview of the Unified Modeling Language (UML)

A B1..3

1, 2, or 3 instances of B are associated with an A

0..*1..1

Customer Order

0..*1..1Role A

Role B

The arrow head on the association implies navigability. In this example, we can determine the customer from the order

Page 54: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Implementation Model for two-way navigability

class Order {private Customer _customer;private Vector _orderlines;.......

class Customer {private Vector _orders;

..........

Page 55: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Interfaces and Abstract Classes

•An interface contains abstract methods and its member variables are static and final. It is primarily a collection of method signatures•An abstract class can have method implementations as well as variables that are not static and final

Page 56: Modeling Concepts and Overview of the Unified Modeling Language (UML)

ClientWindow

toFront()toBack()

MacWindow PresentationManager

Page 57: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Qualified Association

Typically implemented using maps, hashtables, and the like

CustomerRegistry

Customer0..1

SS# : typeSS# : type

0..1

Page 58: Modeling Concepts and Overview of the Unified Modeling Language (UML)

SPECIFICATION PERSPECTIVE ........

class Order {public OrderLine lineItem(Product aProduct);public void addLineItem(Number amount, Product

forProduct);

IMPLEMENTATION PERSPECTIVE:

class Order {private Dictionary _lineItems;

Page 59: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Association Class

PERSON COMPANY

Employmentperiod: dateRange

0..1

* employer

ASSOCIATION CLASS

Page 60: Modeling Concepts and Overview of the Unified Modeling Language (UML)

TSet

insert(T)remove(T)

EmployeeSet

TEMPLATE CLASS

<<bind>>

<Employee>

Page 61: Modeling Concepts and Overview of the Unified Modeling Language (UML)

IMPLEMENTATION.....

class Set <T> {void insert (T newElement);void remove (T anElement);........

Declare.....

Set<Employee> employeeSet;

Page 62: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Value Versus Reference Semantics

•Identity•Sharing•Cardinality•Direction of navigation

Page 63: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Aggregation and Composition

•Aggregation represents a “has-a” relationship and may be used to model “whole/part” relationships

DepartmentUniversity

Page 64: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Aggregation Versus Composition

• In aggregation, there is no link between the lifetimes of the whole and its parts• An aggregation is semantically stronger than an association• A part in an aggregation can be shared by other wholes• Meaning of navigation is the same as in an association

Page 65: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Composition

• Semantically stronger than an aggregation• Characterized by coincident lifetimes of the whole and its parts• Object can be a part of only one whole

FrameWindow

Composition example from Booch et al., (1999)

Page 66: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Reflexive Association

Employee

0..10..*

supervises

supervisor

subordinate

0..10..*

Page 67: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Ternary Associations

Passenger FlightSeatAssignment

Seat

Note: Multiplicity is not shown

Page 68: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Attribute Syntax

• The syntax of an attribute in the UML is: [visibility] name [multiplicity] [ :type ] [= initial value] [{property string}]

Visibility: +, - , or # (public, private, protected)multiplicity: refers to the number of the instances of the

attribute in the classtype: data type

Page 69: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Property String

• changeable (default): value can be modified• addOnly: values can be added, but not removed or changed• frozen: value cannot be changed after object initialization

Page 70: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Syntax for Operations

• The UML has the following syntax for an operation:[visibility] name [ (list of parameters) ] [: return type ][ {poperty string} ]

Syntax for each parameter is:[direction] name :type [=default value]

direction may be in, out, or inout

Page 71: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Property Strings for operations

• isQuery• sequential• concurrent• guarded

Page 72: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Inheritance

•Generalization versus Specialization•Visibility is determined by access directives•Public fields are not good, protected is somewhat better, and private is perhaps the best

Page 73: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Type Promotion (upcasting)

VehiclevehicleID

run()

Automobile

race()

class X { public static void f(Vehicle v) { v.run();}} // Safe type promotion

class X { public static void f(Vehicle v) { v.race();}} // will not work! why? what is the solution?

Page 74: Modeling Concepts and Overview of the Unified Modeling Language (UML)

class Y {public static void g(Vehicle v) {Automobile a = (Automobile) v;a.race();

}}

What will this piece of code do if we pass an instance of a Truck?

class Y {public static void g(Vehicle v) {

if (v instanceOf Automobile) {Automobile a = (Automobile) v;a.race();}

}}

Page 75: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Polymorphism and Dynamic Binding

Device

poll()

D1 D2 D3

Client

Page 76: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Advantages of Polymorphism

• Client knows only about the superclass• Changes to the subclasses do not affect the client as long as the interface is

unaltered• In some languages, recompilation may not be necessary if there are changes to

the subclass that do not affect the interface presented to the client• Pluggability

Page 77: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Class Specialization

•A subclass may specialize its superclass either through extension (Java, C++) or by restriction (C++)•Extension happens when:

1) You add a new behavior2) You override an existing behavior3) You add state information (value or reference)

Page 78: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Dependency

• Dependency may be used to model:1) A refinement of a design feature (remember <<trace>>?)2) Instantiation of a template3) A refinement of an association• A dependency is used to show a “using” relationship• Examples include bind, derive, instantiate, friend, instanceOf, refine, access,

import, become, etc.,

Page 79: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Notes

• Notes are often attached to elements on a diagram

An example of a note

Page 80: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Extension Mechanisms

• Extension mechanisms are provided to accommodate differences among OO languages

• Annotation mechanisms include specifications and adornments• Extension mechanisms permit the designer tointroduce new properties,

constraints, stereotypes, and the like

Page 81: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Extension mechanisms

• Specifications are often descriptions that appear in a document that is not part of the UML diagram, but may be hyperlinked to one

• A graphical representation of text is called an adornment, e.g., + stands for public

• Properties are expressed as tag-value pairs, e.g., { Date created = 12/11/00 }• The tag or value may be implied at times

Page 82: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Constraints

• Constraints are rules that cannot be violated

BookCopyRental

VideoCopy

{or}

Page 83: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Stereotypes

• Stereotypes appear in guillements (e.g., <<actor>>)• Stereotypes may be used with any UML construct - with specialization

relationships, dependency relationships, refinements, plain associations, etc.,

Page 84: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Class Diagram for Order Processing

<<actor>>Telephone Agent

OrderRegistry

CustomerCatalog

name,phone#

order#

ProductCatalog

ItemNumber

Customer

Order

Line ItemCatalogItem

* 1*

1

1

*1..*

1

1

0..1

Page 85: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Developing Class Diagrams

Page 86: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Identifying Classes

• There are three basic approaches to developing class diagrams:1) Identification of noun phrases2) Abstraction3) From use cases

Page 87: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Class Diagrams from noun phrases

• Underline or list all the nouns from a written description of a system• In particular, look for physical objects, roles, events, interactions, and

concepts• Refine the list by checking for redundancy, relevance, clarity (lack of

vagueness), and by eliminating those nouns that stand for attributes, operations, roles, and implementation constructs

Page 88: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Examples from the Library System

• System and member are redundant• you, code, and library card (?) are irrelevant• item number, membership number, author (assuming just name), book/video

status are all atributes• checkout duties is an operation• borrower, borrowed item indicate possible roles

Page 89: Modeling Concepts and Overview of the Unified Modeling Language (UML)

From abstraction

• Use your knowledge of the domain/expertise to identify classes and their relationships

• Some modeling guidelines ....1) Identify “kind of” and “part of’ relationships2) Identify system interactions3) Identify devices that interact with the system4) Determine what information the system has to store, e.g., events, things, interactions, etc.,5) Identify roles

Page 90: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Stock Trading Example

• Some of the classes that we can abstract from the Stock Trading example are:Tangible things: Account, Stock, OrderRoles: customer, service representativeEvents: security transferInteractions: Match (buy and sell orders)

Page 91: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Classes from use cases

• The identification of classes and the resulting class diagram is use-case driven• Identify use cases and then step through each scenario of the use case, each

time ensuring that the class diagram supports the use case• This is not always straight forward and is perhaps best when used in

conjunction with noun identification and abstraction

Page 92: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Pros and Cons

• Advantages of noun identification:1) A mechanical approach that appeals to novices2) Domain knowledge is not required3) Stopping rule is clear• Disadvantages:1) Tedious2) Assumes that a written specification is available3) The quality of the class diagram is dependent on the fidelity of the

specification

Page 93: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Advantages and disadvantages of abstraction

• Efficient• Uses domain expertise• Drawbacks are:1) Extensive knowledge required2) Poor traceability from design & implementation constructs to requirements3) Easy to get bogged down4) Stopping rule is not clear

Page 94: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Pros and cons of using use cases for class identification

• Resulting model is likely to be consistent with behaviors• Good for understanding, explaining, and validating requirements - provides

good traceability from design & implementation back to requirements• Disadvantages:1) There could be hundreds of use cases2) A good knowledge and understanding of the domain is required to write use

cases3) Scoping is a problem4) Not straightforward

Page 95: Modeling Concepts and Overview of the Unified Modeling Language (UML)

A practical approach

• Use a combination of the three approaches• The order in which the approaches are used is not important• Validation is important• Whenever possible, use a domain expert to guide you

Page 96: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Drawing flexible Class Diagrams

Page 97: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Cohesion

• The more diverse a class the less cohesive it is• A class should map on to a single concept or abstraction• High cohesion is desirable• High cohesion may be achieved by:1) Having classes that represent just one abstraction and2) Having methods that do one and only one function

Page 98: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Problems with less cohesive classes

• Difficult to understand• Assumes that two or more abstractions embodied in a class are always in a 1:1

relationship• May lead to a messy inheritance structure

Page 99: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Account class representing two abstractions

Account

LoanAccount CashAccount IndividualAccount CorporateAccount

Page 100: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Cohesive Classes

1..*0..*

LoanAccount CashAccount IndividualAccount CorporateAccount

Account Customerholder

1..*0..*

Page 101: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Increasing Cohesion

• Follow the rules of normalization:Have single-valued attributesA class should contain attributes that really belong to it

Page 102: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Coupling

• Coupling is a measure of how much dependency exists between the classes/objects in a system

• A class that is highly (tightly) coupled knows too much about the world around it

Page 103: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Types of Coupling

• Identity coupling - an object holds a reference to another object. Minimize navigability to reduce this coupling

• Representational Coupling - an object refers to another either by accessing its public data or by invoking its accessor method(s)

• Subclass coupling - occurs when a client holds a reference to a specific class (such as a subclass) rather than to something more abstract

• Inheritance Coupling - Coupling that results from an inheritance structure

Page 104: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Subclass Coupling

VideoCopy

Rental

BookCopy

Page 105: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Reducing Subclass Coupling

VideoCopy

BookCopy

Rental LendableCopy

Page 106: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Inheritance Coupling

CatalogItem

InventoryItem InventoryItem

CatalogItem1..1

0..1

1..1

0..1

Page 107: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Inheritance versus Composition/Delegation

• Use inheritance when:1) There is a “kind of” relationship rather than a “role of”2) No transmutation of subclass objects occurs3) The inheriting classes extend rather than override or nullify superclass

methods4) “kind of” relationships exist among classes in the problem domain (e.g., kind

of roles, transactions, etc.,)

Page 108: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Subclassing a Utility Class

• Subclassing a Utility class (e.g., Vector) is not desirable because:1) We have no control over changes made to Utility classes2) It weakens encapsulation

Page 109: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Class Generalization

• Use superclasses when:1) Two or more classes have common implementation2) Two or more classes share a common interface

Page 110: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Class Specialization

• Subclasses can specialize their superclass by:1) Adding attributes2) Adding associations, i.e., references3) Adding new behavior4) Overriding the method of their superclass

Page 111: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Distinctions based on state

Employee

Manager NonManager

Employee<<abstract>>

Manager

Page 112: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Use aggregation

1..1

Manager NonManager

EmployeeRole<<abstract>>Employee

1..1

Page 113: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Aggregation versus Specialization

• Aggregation is better when:1) Class has different aspects to be specialized2) Properties are not shared by all subclasses3) Multiple Inheritance is used

Page 114: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Placing properties in the right class

• A superclass property should apply to all its subclasses• A shared property should be implemented just once

Page 115: Modeling Concepts and Overview of the Unified Modeling Language (UML)

How do we handle this?

f() has identical implementations in B1 and B2

A

B1

f()

B2

f()

B3

Page 116: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Multiple Inheritance versus Aggregation

• Don’t use Multiple Inheritance when there is no “is-a-kind-of” relationship• An ATM aggregates CardReader, Keyboard, DisplayScreen, and CashDrawer• Parts should be hidden inside the aggregate• Interactions between parts should be through the whole

Page 117: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Reusing parts of an aggregate

1..1

TollBooth

cardInserted()

ATM

cardInserted()

CardReaderCardDriven

cardInserted()

<<interface>>

1..1

Page 118: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Dynamic Diagramming Notation

Page 119: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Static and Dynamic Views

Modeling Activity Static View Dynamic ViewRequirements Analysis Use cases Activity DiagramsDesign Class & Object diagrams Interaction Diagrams and

Statecharts (State-Transition Diagrams)

Page 120: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• A scenario is an instance of a use case, i.e., it is one pass through the use case• Use cases are described using:1) A textual description2) Activity diagrams

Page 121: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Textual Description

• Start with a general description• Factor if necessary• Provide details of steps - main flows, alternative flows including exceptions

Page 122: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Interaction Diagrams

• Interaction diagrams are used to show object interaction in a scenario• They are graphical

:A :B

1: message()

Page 123: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Interaction Diagrams

• An instance of class A sends a message to an instance of class B• message() would correspond to a method defined in class B

:A :B

1: message()

Page 124: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Interaction Diagrams

• There are two types of interaction diagrams:Collaboration Diagrams emphasize links between objects and help one to visualize the structural organization of objects

Sequence Diagrams emphasize the time ordering of messages

Page 125: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 126: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 127: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Interaction Diagram features

: Salesrep

: Order : OrderLine

1: cancel()2: *[for all order lines] cancel()

Page 128: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Iteration in a collaboration diagarm

: Salesrep

: Order

1: cancel()

: OrderLine

2: *[for all order lines] cancel()

Page 129: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Conditional messages

: Salesrep

: Order : OrderLine

1: [ status == pending ] cancel()2: *[for all order lines] cancel()

Condition in a sequence diagram

Page 130: Modeling Concepts and Overview of the Unified Modeling Language (UML)

: Salesrep

: Order

1: [ status == pending ] cancel()

: OrderLine

2: *[for all order lines] cancel()

Conditional message in a collaboration

Page 131: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Branching

:A :B :C

[condition true] x()

[condition false] f()

Page 132: Modeling Concepts and Overview of the Unified Modeling Language (UML)

:A :B

:C

1: [condition true] x()

1: [condition false] f()

Page 133: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Object Creation and Destruction

:A :B

:C

1: x()

2: new()

{new}

Page 134: Modeling Concepts and Overview of the Unified Modeling Language (UML)

:A :B

1: x()

:C

2: new()

Page 135: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Timing Constraints

:A :B

x

y

{ y - x < 5 ms }

Page 136: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Stereotypes for links

• <<association>>• <<global>>• <<local>>• <<parameter>>• <<self>>

Page 137: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 138: Modeling Concepts and Overview of the Unified Modeling Language (UML)

CRC Cards

• Lists class, responsibilities, and collaborations• Good for brainstorming• UML interaction diagrams are more comprehensive

Page 139: Modeling Concepts and Overview of the Unified Modeling Language (UML)

State Machines

Page 140: Modeling Concepts and Overview of the Unified Modeling Language (UML)

State Machines

• May be used to model the dynamics of a system• Used to model the behavior of a single object across all scenarios• Useful for specifying the states that an object goes through in its lifetime, what

triggers the transition, and how the object responds to those events that trigger the transition

Page 141: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• State machines are useful for objects that exhibit meaningful state-based behavior, i.e., when an object’s response to events depends on the state that it is in and when it is possible for the object to pass through a set of states (some of which may be meaningful), or when the order of execution of an object’s methods is important

Page 142: Modeling Concepts and Overview of the Unified Modeling Language (UML)

State Machines

• A state is a particular condition that an object (with specific values for its attributes and links) is in during which time it may perform some activity or wait for the occurrence of an event

• Transitions from one state to another are triggered by events• An event may be a signal (e.g., a hardware interrupt) or a message (e.g., the

invocation of a method)

Page 143: Modeling Concepts and Overview of the Unified Modeling Language (UML)

State Machines

• Activities may be performed by an object when it is in a particular state• Time for an activity is not negligible• Transitions are assumed to be instantaneous • Actions carried out during transitions, therefore, take very little time

Page 144: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Parts of a state (Booch et al., 1999)

• Unique name (a string) - it could also be anonymous• Entry and exit actions• Transition to self, i.e., it remains in the same state• Substates - nested structures which may involve sequential or concurrent

substates• Deferred events - queued to be handled by the object when it is in a different

state

Page 145: Modeling Concepts and Overview of the Unified Modeling Language (UML)

States

• Initial state is represented by a filled black circle • Final state is represented by a filled black circle surrounded by a circle • Initial and final states are called psuedostates

Page 146: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Triggers for Transitions

• When an event/message is received• Event/message and a guarding condition occur• A condition becomes true• A certain amount of time elapses• A triggerless transition may occur when the source state completes its activity

Page 147: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Receipt of events

Two possible states of a Book class

NotAvailable Available

return

Page 148: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Message and a guard condition

Two possible states of a Book class

NotAvailable Available

return [! onHold ]

Page 149: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Condition becomes true

Available NotAvailable

when (numberAvailable == 0)

Page 150: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Transition after a certain time

Possible states of a VCR

Stopped PowerOffafter(60 seconds)

Page 151: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Actions during a transition

Available BackOrdered

allocateFromInventory(quantity) [ quantity > currentInventory]^warehouse.backorderItem(item#, rorderQuantity)

when (currentInventory == 0 ) ^warehouse.backorderItem(item#, rorderQuantity)

itemAvailable(quantity) / currentInventory += quantity

Page 152: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Composite States

Open Pending

Entered

Funded

Entered

Funded

Canceled

Fulfilled

when(committed)

when(funded)

cancel

when(noItemsPending)

A Composite State (Fig. 5.37 from book

Page 153: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Open Pending

Entered

Funded

Entered

Funded

Canceled

Fulfilled

when(funded)

cancel

when(noItemsPending)

Semantically identical to previous figure

when(committed)

Page 154: Modeling Concepts and Overview of the Unified Modeling Language (UML)

History States

Open Pending

Entered

Funded

Entered

Funded

Canceled

Fulfilled

when(funded)

cancel

when(noItemsPending)

when(committed)

OnHold

hold

H

continue

Page 155: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Shallow and Deep History

• The H is for shallow history, which is all right for one level of nesting• Shallow history does not remember down to the innermost nested state• Use deep history, represented by a H*, to remember down to the innermost

nested state

Page 156: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Parallel State Machines

Available BackOrderedAvailable BackOrdered

when (currentInventory =

Listed UnListedListed UnListedremoveFromCatalog

addToCatalog

0)

....

Page 157: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Parallel State Machines

• Each of the two state machines (one for the Inventory and the other for the Catalog) executes in parallel

• Parallel state machines normally imply a lack of cohesion for the class • In this example, management of inventory could be moved to a separate class

( remember Inheritance Coupling? from chapter 4)

Page 158: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Parallel States

Pending

Canceling

entry/creditIssuer.creditAccount

entry/ catalogItem.addToInventory

Canceled

entry/creditIssuer.creditAccount

entry/ catalogItem.addToInventory

cancel

cancel

credited

added

Join - bothmust complete

Fork - both statesentered at the same

time

Page 159: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Developing Dynamic Diagrams

Page 160: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Top-Down versus Bottom-Up Approach

• Top-Down Approach - start with use cases and step through scenarios to identify specific objects, their methods, and the links between objects

• Bottom-Up Approach - start with specific object methods, attribute, and links, and then refine/expand these responsibilities as each scenario is validated

• The primary purpose of both approaches is the same, viz., to identify the objects and their methods, attributes, and links, and also to have some idea of what each method must do

Page 161: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Design artifacts

• Design artifacts for both approaches include:Use Cases and their specificationsScenarios for each use caseInteraction diagram for each scenarioStatecharts for classes that have complex/interesting state-based behaviorChanges to the class diagram

Page 162: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Top-Down Approach

• Use case driven• Steps include:

Identification of use casesSpecification of use casesDefinition of a scenario (an instance of the use case)Drawing an interaction diagram for each scenario

Page 163: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Steps continued

Identification of object methods in the interaction diagramsAlteration of class diagrams to ensure consistency with interaction diagramsDevelopment of state machines to understand the behavior of objects across scenarios, i.e., during its lifetime

Page 164: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Identifying Use Cases

• Jacobson’s ApproachIdentify actorsFind out what interactions the actor initiates with the system and what interactions the system initiates with the actor

• Determine what use cases cause the creation, deletion, and modification of objects that belong to classes in your class diagram

• Verb phrases may reveal some use cases

Page 165: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Stock Trading Example

• The actor is the Service Representative• Some use cases....

Enter a buy orderEnter a sell orderCancel an existing orderCreate a new accountExecute a transfer of stock into the system

Page 166: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Stock Trading example contd.

Execute a transfer of stock out of the systemExecute a transfer of cash into the systemExecute a transfer of cash out of the systemQuery the systemWhat other use cases can you identify?How did you identify them?

Page 167: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Description of each use case

• Describe the use case• Detail the steps involved• If necessary, draw an activity diagram• Come up with a textual description that includes the trigger for the use case

and pre- and post-conditions

Page 168: Modeling Concepts and Overview of the Unified Modeling Language (UML)

A sequence diagram

: TradingSystemRep : Rep

1: enterBuyOrder

Page 169: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Another scenario

Rep : Rep : TradingSystem

: Account

1: enterBuyOrder2: getBalance

Page 170: Modeling Concepts and Overview of the Unified Modeling Language (UML)

The “Happy” Path

Rep : Rep : TradingSystem

: Account newBuyOrder : BuyOrder

: Stock

1: enterBuyOrder2: getBalance

3: new

4: addBuyOrder(newBuyOrder)

Page 171: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Bottom-Up Design

• Identify classes• Determine their responsibilities - state and behavior• Validate responsibilities using relevant scenarios• Draw an interaction diagram for each scenario to ensure that all

responsibilities have been identified. Add/modify responsibilities as needed

Page 172: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Identifying classes and responsibilities

• Book, BookCopy, Video, VideoCopy, LibraryCard, LibraryMember, LoanTransaction

• A BookCopy must know:Its unique item numberIts status (available or not)It must be able to check itself outIt must be able to return itself (check in)

Page 173: Modeling Concepts and Overview of the Unified Modeling Language (UML)

The Model

1..1*

1..*

1..1

LibraryMembernameaddress

setName( )setAddress( )okToBorrow( )

1..11..1

LibraryCardmemberNumber : StringexpiryDate : Date

renew( )

1..11..1

0..*1..1

LoanTransactioncheckOutDate : DatedueDate : Date

isOverdue( )0..*1..1

rented1..1

0..*

BookCopycall#

VideoCopyvideo#

Lendableitem#

checkIn( )checkOut( )

<<Abstract>>1..1

0..*

1..1

1..*

Library

checkIn ()checkOut ()

<<facade>>

1..1*

1..*

1..1

LendableTitletitle

1..1

1..*

0..*

1..1

0..*

1..1

Page 174: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Validating the Model

• Use scenarios• CheckOut scenario is as follows:

a) Clerk provides member# and item#b) System checks to see if it is okay to borrowc) System checks out the item

Page 175: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Assigning Behaviors

• Where should the method okToBorrow() really be?• Who creates the Loan Transaction? (Lendable perhaps)• Who should inform the LibraryMember object about the new

LoanTransaction?• How is the due date determined?

Page 176: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Checking out a book

rep:Clerk :Library aLendable:Lendable

:LendableTitle lt:LoanTransaction

:LibraryCard

1: checkOut(1001, 2345)2: okToBorrow()

3: checkOut()4: loanPeriod()

5: new(lc, aLendable, today + 14)6: addLoanTransaction(lt)

Page 177: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Flexibility Guidelines for Interaction Diagrams

Page 178: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Flexibility Guidelines

• Cohesion - class & method cohesion• Distributing Behavior - Behavior of an activity to be done on a state should be

in the object that has that state• Extension vs reuse - extensibility often reduces reusability

Page 179: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Exception to cohesive classes

• The facade is an exception to the principle of having highly cohesive classes• Although it is not cohesive, it serves the important purpose of reducing

coupling

Page 180: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Class Cohesion

Consider the following partial class diagram..

Machinestatename

MaintenanceScheduledateLastMaintainedperiod

1..11..1 1..11..1

Page 181: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Class cohesion continued..

• Why can’t we combine the two classes (as the multiplicity is 1:1)?a) Machine responds to a stimulus while MaintenanceSchedule produces a

stimulusb) They may not always be in a 1:1 relationship. Assuming that they are results in

a design that is not extensible

Page 182: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• Write a one-sentence description of each responsibility. If it turns out to be a compound sentence that describes multiple activities, consider having another class

• Incorporating these one-sentence descriptions in the source code may help developers to maintain and enhance/extend the current design

Page 183: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Tradeoffs

• As mentioned earlier, a facade is an exception to cohesive classes, but one that is deemed necessary in the interests of reducing coupling

• Cohesion may also be sacrificed in the interests of systems performance

Page 184: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Distributing Behavior

• Behavior should be evenly distributed - avoid objects that have just data and no behavior

• Avoid controllers that make decisions based on state information obtained from other objects

• Reduce representational coupling by exposing the client to abstract rather that specific details

Page 185: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Distributing behavior contd.,

• Clients should use an assertive style that tells the service objects what to do rather than an inquisitive style where information is obtained from the service object and acted upon by the client

Page 186: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Examples

• Consider the following class diagrams..

ElevatorControl

handleRequest( )

Elevatorlocationdirection

getProximity(req:Request):int0..*1..11..1 0..*

Elevatorlocationdirection

direction()location()

ElevatorControl

handleRequest( ) 0..*1..11..1 0..*

Page 187: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Which of the two diagrams is better and why?

The second has more even distribution of behavior, allows for parallel computations, and is more extensible

The first may be desirable when centralized control is required, perhaps for performance reasons or because of other constraints

Page 188: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Stock Trading Example

Consider the following...

2: cancel()

:TradingSystem

:Order

1: getStatus()

:TradingSystem

:Order

1: cancel()

Page 189: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• Which is better and why?• Likewise, consider the following....

:TradingSystem

:Account

1: getBalance()

:TradingSystem

:Account

1: fundBuy(amount)

Page 190: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• fundBuy(amount) is better because:a) The state and behavior are in Accountb) If updates to balance have to be made, the behavior should be in the Account

classc) If there are different types of accounts, each of which has a different way of

funding, then this approach is better

Note: We should really distinguish between balance and what is available

Page 191: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• Where should the “match orders” behavior be?Putting it in the Order class has the following drawbacks:1) A sell order would have to go through every buy order2) Does not lend itself to parallel processing

Perhaps a good idea to move the behavior to the Stock class

Page 192: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Extension versus Reuse

• Extensibility often reduces reusability because application-specific methods may have to be added to a class

• This is a result of distributing behavior in order to avoid controller classes and to keep state and behavior togetherIf reuse is a major goal, a different set of guidelines may have to be used

Page 193: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Account Example

• For an Account class to be reusable, it should provide an interface/basic functionality that is common to all accounts

• An account that deals only with cash is less reusable than one that holds a variety of assets

Page 194: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Combining Extension and Reuse

• Application-specific class may use a more generic/reusable class through composition

1..1

Accountbalance : float

deposit(amount:float)withdraw(amount:float)currentBalance()

StockTradingAccount

fundBuy(amount:float)unfundBuy(amount:float) 1..1

Page 195: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Architectural Models

Page 196: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Architectural Models

• Issues such as layering/subsystems, persistence, and deployment become important in large systems

• Decomposition is a useful technique for determining logical and/or physical blocks that make up the architecture of the system

• Logical blocks are layers or subsystems that are conceptual entities

Page 197: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• Physical blocks are things such as the hardware on which the logical blocks reside (as source or executables, e.g., *.cpp, *.exe)

• These blocks (logical and physical) may be nested • Decomposition is mainly a top-down approach

Page 198: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Composition

• Composition is more of a bottom-up approach in which smaller units (such as specific use cases or classes) could be grouped together to form logical blocks

• Logical or physical considerations may be used to guide the grouping process

Page 199: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Architectural Perspectives

• Logical - emphasizes the layers/subsytems that comprise the overall system. A Package Diagram provides a visual model of a logical architecure

• Hardware - When multiple hardware units are used, a Deployment Diagram can be used to visualize their relationships and how the various logical and physical blocks are distributed

Page 200: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Architectural perspectives continued...

• Process - this view focuses on the threads and/or processes that are an integral part of concurrent applications. Issues such as synchronization, locking, throughput, and performance are important considerations in this view

• Implementation - A Component Diagram presents a view of all source, binaries, and executables, and their relationships.

• When used in conjunction (through superimposition) with static and dynamic diagrams, these views present a comprehensive understanding of the architecture

Page 201: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Logical architecture

• Conceptual grouping of layers/subsystems, guided by functional cohesion• Each layer is responsible for a different function• Example: Presentation, Application, and Persistence layers

Page 202: Modeling Concepts and Overview of the Unified Modeling Language (UML)

PersistenceLayer

Application Layer

TradingSystem<<facade>>

AccountManagement

<<subsystem>

SecurityManagement

<<subsystem>>

OrderManagement<<subsystem>>

<<imports>>

<<imports>>

<<imports>>

<<imports>>

<<imports>>

<<imports>>

PresentationLayer

<<imports>>

<<imports>>

Page 203: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Logical Architecture

• A package contains logically related classes or logically related use cases• Decomposition is typically used when the architecture is known before hand• Having different packages as part of the overall system can help in assigning

different aspects of software development to different teams

Page 204: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• Dependency between layers/packages can be shown using the <<imports>> stereotype

• It is possible to nest packages to any depth• A class inside a package may or may not be visible to the outside world• A plus (+) sign next to the class name implies that the class can be accessed by

other packages• A minus (-) sign next to the class name implies that the class is hidden from

other packages

Page 205: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Criteria for partitioning

• Functional Cohesion• Unit of reuse• Access Control• Delivery Units• Physical configuration of components

Page 206: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Hardware Architecture

• Depicted as nodes and their interconnections• A node is a computational unit with memory and quite possibly computing /

processing capability• Nodes are physically connected to other nodes

Page 207: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Hardware Architecture...

• A Deployment Diagram shows nodes and their relationships• Cardinality constraints may be shown both for the nodes and their

relationships

Page 208: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Deployment Diagram

Account Server

Client

Order Server

Account Database Server

Order Database Server

<<ethernet>><<ethernet>>

Page 209: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• Deployment Diagrams are useful for showing the hardware architecture of:a) Embedded Systemsb) Client/Server Systemsc) Fully Distributed Systems

• A deployment diagram instance may be drawn to show an occurrence of node instances and their connections

• Nodes from the Deployment Diagram may be superimposed on class (& package) and interaction (mainly collaboration) diagrams

Page 210: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 211: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• Use the <<becomes>> stereotype for a dependency to show object migration from one processor to another

• Example(Fig. 8.16, Page 288), an order object from the Order Database Server “migrates’ to the Order Server when it is retrieved from the database

Page 212: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Process Architecture

• Most applications use some form of concurrency to maximize system throughput and to improve the overall performance of the system

• Processes and threads are frequently used to achieve concurrency• A process is a heavyweight flow of control, independent of other processes with

which it runs concurrently

Page 213: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• Inter-process switching and communication are relatively expensive• A thread is a lightweight flow of control that runs concurrently with other

threads within a process• Threads within a process share the same heap space and, therefore, it is

relatively inexpensive to switch between threads

Page 214: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• An active object is one that has the ability to initiate control activity on its own by virtue of owing a thread or a process

• The spawning of processes and threads is mainly a function of the Operating System

• Languages such as Java support multithreading• An active object in Java is an instance of a class that either specializes the

Thread class or implements the runnable interface

Page 215: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Class Synchronization

• The use of threads requires careful thought in order to avoid integrity problems

• Designs should take particular care to avoid improper locking and deadlock problems

• Levels of locking include:• A sequential class or method• A concurrent class or method• A guarded class

Page 216: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Sequential class or method

• No locks are used• An instance can have two (or more) of its methods running concurrently• Does not guarantee integrity under concurrent operations• A sequential class has only sequential methods

Page 217: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Concurrent class or method

• A lock on the instance is obtained when a concurrent method is run• Lock is released when the method completes execution• If a lock on the object is not available, the calling thread or process waits• All methods in a concurrent class are concurrent

Page 218: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Guarded class

• Client is responsible for locking and unlocking an object whose class is guarded

• The methods to lock and unlock are in the guarded class• If an instance of the guarded class is locked, the client must wait until it is

available

Page 219: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Concurrent or Guarded?

• In most cases, concurrent locking is preferable because:1. Client code is more readable and maintainable2. No dependency on client3. It may be easier to avoid deadlocks4. Clients are immune to changes made to the classes on whose services they

depend

Page 220: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Guarded is preferable when...

• The client wishes to treat more than method as a single, atomic operation• Example: Applying a stock split to all StockHolding and Order instances for a

given security

Page 221: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Synchronization control of classes

• Classes whose instances are likely to be affected by the concurrent execution of two or more use cases need to be synchronized

Page 222: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Process or Thread Synchronization

• Processes or threads may also have to be synchronized• Operating Systems have mechanisms for synchronizing processes• A Rendezvous Pattern may be used to synchronize threads

Page 223: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Synchronization options

• Depending on how long a client is willing to wait for a lock on an instance, one of the following schemes may be used:

1. Asynchronous2. Synchronous3. Timeout4. Balking5. Simple

Page 224: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Interaction Diagram showing threads

Page 225: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 226: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Process Scheduling

• How long a process executes depends on whether preemptive or non-preemptive scheduling is being used

• The order of execution depends on whether it is priority-based, round-robin, or a combination

Page 227: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Implementation Architecture

• A component diagram is used to show components and their relationships• A component such as a source file (eg., a cpp or a .h file), binary, or an

executable is physical and substitutable• A dependency relationship often exists between components

Page 228: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Order.cpp

Order.hCustomer.h

Page 229: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• Interface dependencies may be shown on a component diagram• Superimposing the hardware architecture (Deployment Diagram) on the

implementation architecture gives an idea of how the components are distributed in an application

Page 230: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Reuse

Page 231: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Reuse

• Avoid building from scratch• Faster development time• Higher quality• Different levels of granularity (single class to a framework)• Reuse may be implementation-based (e.g., a class) or conceptual (e.g., a

design pattern)

Page 232: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Reuse of classes

• Perhaps the simplest• Reuse may be achieved through inheritance or delegation

AccountStockAccount

AbstractAccount

SpecificAccount

Page 233: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Inheritance or delegation

• Inheritance may be easier to implement, but some methods may have to be overriden

• Inheritance commits relationships at compile-time• Inheritance is not very useful if some of the public methods have to be hidden

from the client• Inheritance assumes that subclasses are associated with only one superclass

Page 234: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Inheritance vs delegation

• Inheritance may be the only option if there is a need to use protected methods and fields of a library class

• Delegation, on the other hand, gives run-time flexibility

Page 235: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Generic Programming & Reuse

• C++ uses the notion of templates to provide generic classes that may be reused• The more abstract the class the more reusable it is• Class-based reuse is easier for application-independent abstractions

Page 236: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Component reuse

• Components are a coherent unit that realize a set of interfaces which they offer to other components

• Components are physical elements that can be replaced• The purpose of a component is usually well-defined in the context of an

application• A component usually consists of many classes and is thus a larger scale

building block than a class

Page 237: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Component Example

Inventory Management<<component>>

Method parameters are not shown

+InventoryManagementFacade

allocateFromInventory()addToInventory()currentInventory()defineInventoryItem()removeInventoryItem()

1..1

-ItemRegistry

find(item#:int)1..1

-InventoryItem

allocateFromInventory()addToInventory()currentInventory()

0..1

item# : type

0..1

item# : type

An Inventory Management Component

Page 238: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Framework Reuse

• Customization of components does not normally involve internal specialization

• External behavior and addition of other components is what allows for component customization

• Frameworks allow for internal specialization

Page 239: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• The commonality of many applications are often embodied in a framework, e.g., handling reservations for different applications typically involves activities that are common to all entities being reserved

• A white-box framework allows for application-specific implementation through inheritance (by offering set of abstractions whose interfaces are defined and implemented)

Page 240: Modeling Concepts and Overview of the Unified Modeling Language (UML)

• A black-box framework allows for customization through additional classes that implement the interfaces defined in the framework, i.e., you just plug in classes that conform to the interface or role

• To summarize, with white-box frameworks you must understand the classes in them in order to tailor them for an application and in black-box frameworks you must understand what interfaces have to be implemented

Page 241: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 242: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 243: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Black-Box Framework Example

Page 244: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 245: Modeling Concepts and Overview of the Unified Modeling Language (UML)

Role-Based Design

• Clients should be coupled to roles rather than to specific classes• This gives more flexibility• Use interfaces to accomplish this

Page 246: Modeling Concepts and Overview of the Unified Modeling Language (UML)

How do we improve this?

Empty implementations

Client

Device

reset()pause()resume()poll()

<<abstract>>

0..*0..* 0..*0..*

D1

reset()pause()poll()resume()

D2

reset()pause()resume()

D3

reset()poll()

Page 247: Modeling Concepts and Overview of the Unified Modeling Language (UML)
Page 248: Modeling Concepts and Overview of the Unified Modeling Language (UML)

References

• Booch, Rumbaugh, and Jacobson, “The Unified Modeling Language User Guide,” Addison-Wesley, 1999

• Coad and Mayfield, “Java Design – Building Better Apps and Applets,” Yourdon Press Computing Series, 1999

• Fowler with Kendall Scott, “UML Distilled: Applying the Standard Object Modeling Language,” Addison-Wesley, 1997

• Gamma, Helm, Johnson, and Vlissides, “Design Patterns: Elements of Reusable Object-Oriented Software,"”Addison-Wesley, 1995

• Pooley and Stevens, “Using UML – Software Engineering with Objects and Components,” Addison-Wesley, 1999

• Richter, Charles, “Designing Flexible Object-Oriented Systems with UML,” Macmillan Technical Publishing, 1999

• Schneider, Geri and Winters, Jason, “Applying Use Cases – A Practical Guide,” Addison-Wesley, 1997