You are on page 1of 75

Object Oriented Analysis and Design

Using the UML


Version 4.2

Introduction to Object Orientation

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 1
Objectives: Introduction to Object Orientation
Understand the basic principles of object
orientation
Understand the basic concepts and terms
of object orientation and the associated
UML notation
Appreciate the strengths of object
orientation
Understand some basic UML modeling
mechanisms

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 2
Introduction to Object Orientation Topics
Basic Principles of Object Orientation
Basic Concepts of Object Orientation
Strengths of Object Orientation
General UML Modeling Mechanisms

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 3
Basic Principles of Object Orientation

Object Orientation

Encapsulation
Abstraction

Modularity

Hierarchy
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 4
What is Abstraction?

Salesperson
Not saying
Which
salesperson
– just a
salesperson
in general!!!
Product
Customer

Manages Complexity
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 5
What is Encapsulation?
Hide implementation from clients
Clients depend on interface

How does an object encapsulate?


What does it encapsulate?

Improves Resiliency
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 6
What is Modularity?
The breaking up of something complex into
manageable pieces
Order
Entry

Order Processing
System Order
Fulfillment

Billing

Manages Complexity
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 7
What is Hierarchy?
Levels of abstraction Asset
Increasing
abstraction

BankAccount Security RealEstate

Savings Checking Stock Bond

Decreasing Elements at the same level of the hierarchy


abstraction should be at the same level of abstraction
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 8
Introduction to Object Orientation Topics
Basic Principles of Object Orientation
Basic Concepts of Object Orientation
Strengths of Object Orientation
General UML Modeling Mechanisms

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 9
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 10
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 11
What is an Object?
Informally, an object represents an entity,
either physical, conceptual, or software
Physical entity

Truck

Conceptual entity
Chemical Process

Software entity Linked List

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 12
A More Formal Definition
An object is a concept, abstraction, or thing
with sharp boundaries and meaning for an
application
An object is something that has:
State
Behavior
Identity

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 13
Representing Objects
An object is represented as rectangles with
underlined names

: Professor
a + b = 10

ProfessorClark
Class Name Only
Professor Clark
ProfessorClark :
Professor Object Name Only

Class and Object Name


(stay tuned for classes)
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 14
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 15
What is a Class?
A class is a description of a group of objects
with common properties (attributes),
behavior (operations), relationships, and
semantics
An object is an instance of a class
A class is an abstraction in that it:
Emphasizes relevant characteristics
Suppresses other characteristics

OO Principle: Abstraction
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 16
Sample Class

Class
Course
Properties Behavior
Name Add a student
Location Delete a student
a + b = 10
Days offered Get course roster
Credit hours Determine if it is full
Start time
End time

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 17
Representing Classes
A class is represented using a
compartmented rectangle

a + b = 10
Professor

Professor Clark

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 18
Class Compartments
A class is comprised of three sections
The first section contains the class name
The second section shows the structure
(attributes)
The third section shows the behavior
(operations)
Class Name Professor
name
Attributes empID
Operations create( )
save( )
delete( )
change( )

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 19
Classes of Objects
How many classes do you see?

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 20
The Relationship Between Classes and Objects
A class is an abstract definition of an object
It defines the structure and behavior of each
object in the class
It serves as a template for creating objects
Objects are grouped into classes
Objects Class

Professor

Professor Smith Professor Mellon

Professor Jones
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 21
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 22
What is an Attribute?

Object
Class

Attribute Attribute Value


:CourseOffering
number = 101
startTime = 900
CourseOffering endTime = 1100
number
startTime
endTime :CourseOffering
number = 104
startTime = 1300
endTime = 1500

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 23
Visibility of the Attributes
+ public
# protected
- private
~ package (default)
/ derived
Underline Static attributes
Derived Attribute(/): Not stored, but can be
computed from other attribute values.
E.g. Age can be counted from Date of Birth

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 24
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 25
What is an Operation/Methods?

CourseOffering
Class
addStudent
deleteStudent
getStartTime
Operation getEndTime

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 26
Class Operations/Methods
Visibility name (parameters): return_type
Visibility:
+ public
# protected
- private
~ package (default)
Underline Static Methods
Omit return_type on constructors and when
return type is void.

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 27
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 28
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 29
Polymorphism
One of the most useful programming
techniques of the object-oriented
paradigm.
Means “Many forms” - is the ability to
treat an object of any subclass of a
base class as if it were an object of the
base class.
A base class has, therefore, many
forms: the base class itself, and any of
its subclasses.
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 30
What is Polymorphism?
The ability to hide many different
implementations behind a single interface

Manufacturer B
Manufacturer A Manufacturer C

OO Principle:
Encapsulation

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 31
Polymorphism in Java
To use an object of type Liquid, you must
create aLiquid object with new and store
the returned reference in a variable:
Liquid myFavoriteBeverage = new
Liquid();
myFavoriteBeverage variable holds a
reference to a Liquid object. This is a
sensible arrangement;
However, with the help of polymorphism,
you can assign a reference to any object
that is-a Liquid to a variable of
type Liquid.
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 32
Polymorphism in Java

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 33
Polymorphism in Java
Hence any of the following assignments
will also work:
Liquid myFavoriteBeverage = new
Coffee();
// or...
Liquid myFavoriteBeverage = new
Milk();

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 34
What is an Interface?
Interfaces formalize polymorphism
Interfaces support “plug-and-play”
architectures
Tube
<<interface>>
Shape
Pyramid
Draw
Move
Scale
Rotate Cube

Realization relationship (stay tuned for realization relationships)


OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 35
Interface Representations
Tube
Elided/Iconic
Representation
(“lollipop”) Pyramid

Shape Cube

Canonical Tube
(Class/Stereotype) <<interface>>
Representation Shape
Pyramid
Draw
Move
Scale
Rotate Cube
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 36
(stay tuned for realization relationships)
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 37
What is a Component?
A non-trivial, nearly independent, and
replaceable part of a system that fulfills a
clear function in the context of a well-
defined architecture
A component may be
A source code component OO Principle:
A run time components or Encapsulation
An executable component

Source File <<EXE>> <<DLL>>


Name Executable Component
Name Component Name
Interface
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 38
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 39
What is a Package?
A package is a general purpose mechanism
for organizing elements into groups
A model element which can contain other
model elements

OO Principle:
Package Name Modularity

Uses
Organize the model under development
A unit of configuration management
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 40
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 41
What is a Subsystem?
A combination of a package (can contain
other model elements) and a class (has
behavior)
Realizes one or more interfaces which
define its behavior
Realization
Subsystem
<<subsystem>>
Interface Subsystem Name
Interface

OO Principles: Encapsulation and Modularity


(stay tuned for realization relationship)
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 42
Subsystems and Components
Components are the physical realization of
an abstraction in the design
Subsystems can be used to represent the
component in the design
Design Model Implementation Model

<<subsystem>> Component
Component Name Name
Component Component
Interface Interface

OO Principles: Encapsulation and Modularity


OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 43
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 44
Relationships
Association
Aggregation
Composition
Dependency
Generalization
Realization

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 45
Relationships: Association
Models a semantic connection among
classes
Association Name

Professor Works for University

Association
Role Names

Class University
Professor
Employee Employer

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 46
Relationships: Aggregation
A special form of association that models a
whole-part relationship between an
aggregate (the whole) and its parts
Whole Part

Student Schedule

Aggregation

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 47
Relationships: Composition
A form of aggregation with strong
ownership and coincident lifetimes
The parts cannot survive the whole/aggregate
Whole Part

Student Schedule

Aggregation

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 48
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 49
Association: Multiplicity and Navigation
Multiplicity defines how many objects
participate in a relationships
The number of instances of one class related
to ONE instance of the other class
Specified for each end of the association
Associations and aggregations are bi-
directional by default, but it is often
desirable to restrict navigation to one
direction
If navigation is restricted, an arrowhead is
added to indicate the direction of the navigation

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 50
Association: Multiplicity
Unspecified
Exactly one 1
Zero or more (many, unlimited) 0..*
*

One or more 1..*

Zero or one 0..1

Specified range 2..4

Multiple, disjoint ranges 2, 4..6

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 51
Example: Multiplicity and Navigation

Multiplicity

Student 1 0..* Schedule

Navigation

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 52
Relationships: Dependency
A relationship between two model elements
where a change in one may cause a
change in the other
Non-structural, “using” relationship
Client Supplier Component
Class

Package Client Supplier


Dependency
relationship

ClientPackage SupplierPackage
Dependency
relationship
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 53
Relationships: Generalization
A relationship among classes where one
class shares the structure and/or behavior
of one or more classes
Defines a hierarchy of abstractions in which
a subclass inherits from one or more
superclasses
Single inheritance
Multiple inheritance
Generalization is an “is-a-kind of”
relationship

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 54
Example: Single Inheritance
One class inherits from another
Ancestor

Account
balance
name
Superclass number
(parent) Withdraw()
CreateStatement()
Generalization
Relationship

Checking Savings

Subclasses Withdraw() GetInterest()


Withdraw()

Descendents
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 55
Example: Multiple Inheritance
A class can inherit from several other
classes
FlyingThing Animal

multiple
inheritance

Airplane Helicopter Bird Wolf Horse

Use multiple inheritance only when needed, and


always with caution !
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 56
What Gets Inherited?
A subclass inherits its parent’s attributes,
operations, and relationships
A subclass may:
Add additional attributes, operations,
relationships
Redefine inherited operations
Common attributes, operations, and/or
relationships are shown at the highest
applicable level in the hierarchy

Inheritance leverages the similarities among classes


OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 57
Example: What Gets Inherited

GroundVehicle
owner Person
Superclass weight
(parent) licenseNumber 0..* 1

register( )
generalization

Car Truck Trailer


Subclass size tonnage
getTax( )

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 58
Relationships: Realization
One classifier serves as the contract that
the other classifier agrees to carry out
Found between:
Interfaces and the classifiers that realize them
Class Component
Subsystem
Interface Interface
Interface
Elided form
Use cases and the collaborations that realize
them
Canonical form

Use Case Use-Case Realization


OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 59
In
Basic Principles of Object Orientation
Basic Concepts of Object Orientation
Strengths of Object Orientation
General UML Modeling Mechanisms

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 60
Strengths of Object Orientation
A single paradigm
Facilitates architectural and code reuse
Models more closely reflect the real world
More accurately describe corporate data and
processes
Decomposed based on natural partitioning
Easier to understand and maintain
Stability
A small change in requirements does not mean
massive changes in the system under
development
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 61
Class Diagram for the Sales Example

Sale

seller buyer item sold shipping mechanism


Salesperson Customer Product Vehicle

Corporate Individual Truck Train

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 62
Effect of Requirements Change
Suppose you need a
new type of shipping
vehicle ... Sale

seller buyer item sold shipping mechanism


Salesperson Customer Product Vehicle

Corporate Individual Truck Train Airplane

Change involves adding a new subclass


OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 63
Introduction to Object Orientation Topics
Basic Principles of Object Orientation
Basic Concepts of Object Orientation
Strengths of Object Orientation
General UML Modeling Mechanisms

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 64
Stereotypes
Classify and extend the UML notational
elements
Define a new model element in terms of
another model element
May be applied to all modeling elements
Represented with name in guillemets or as
a different icon
<<boundary>>
MyBoundaryClass

MyBoundaryClass

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 65
Example: Stereotypes

<<boundary>>

<<boundary>>
Sample boundary class (stereotype)
<<trace>> Stereotype of ‘dependency relation’
DesignClass Stereotype of <<Processor>>

These create new symbols using


accustomed graphics.

<<Processor>>
Processor #1 Processor #1

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 66
Notes
A note can be added to any UML element
Notes may be added to add more
information to the diagram
It is a ‘dog eared’ rectangle
The note may be anchored to an element
with a dashed line
There can be up to one
MaintainScheduleForm per
MaintainScheduleForm user session.

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 67
Tagged Values
Extensions of the properties, or specific
attributes, of a UML element
Some properties are defined by UML
Persistence
Location (e.g., client, server)
Properties can be created by UML
modelers for any purpose

PersistentClass
{persistence} anObject : ClassA
{location=server}

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 68
Constraints
Supports the addition of new rules or
modification of existing rules

Member 1
Professor Department
1..*
{subset}
Department Head
1 1

This notation is used to capture two relationships between Professor-type objects


and Department-type objects; where one relationship is a subset of another….

Shows how UML can be tailored to correctly modeling exact relationships….


OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 69
Review: Introduction to Object Orientation
What are the four basic principles of object
orientation? Provide a brief description of
each.
What is an Object and what is a Class?
What is the difference between them?
What is an Attribute?
What is an Operation?
What is an Interface? What is
Polymorphism?
What is a Component?
(continued)
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 70
Review: Introduction to Object Orientation (cont.)
What is a Package?
What is Subsystem? How does it relate to
a Component? How does it relate to a
package? How does it relate to a class?
Name the 4 basic UML relationships and
describe each.
Describe the strengths of object orientation.
Name and describe some general UML
mechanisms.
What are stereotypes? Name some
common uses of stereotypes.
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 71
The Three Models of OO Development
The three models are used to describe
a system from different view points:
The Class model for the objects in the
system and their relationships
The State model for the life history of
objects
The Interaction model for the
interactions amongst the objects.
Each model applies during all stages
of development.
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 72
Class Model

Describes the static structure of


the objects and their relationships.
Defines the context for software
development.
Contains Class Diagrams.
Class Diagram: is a graph whose
nodes are classes and whose arcs
are relationships among classes.

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 73
State Model

Describes the aspects of an object


that change over time.
Specifies and implements control
with State diagrams.
State Diagram: is a graph whose
nodes are states and whose arcs
are transitions between states
caused by events.

OOAD Using the UML - Introduction to Object Orientation, v 4.2


Copyright  1998-1999 Rational Software, all rights reserved 74
Interaction Model
Describes how the objects in a system
cooperate to achieve broader results.
Starts with Use Cases that are elaborated
with Sequence and Activity Diagrams.
Use Case: focuses on the functionality of
the system, ie. What it does for the user?
Sequence Diagram: shows the objects
that interact and the time sequence of
their interactions.
Activity Diagram: elaborates important
processing steps.
OOAD Using the UML - Introduction to Object Orientation, v 4.2
Copyright  1998-1999 Rational Software, all rights reserved 75

You might also like