1/4/20
Object Oriented Analysis and
Design
BY
DR. L. RANATHUNGA
Additional References
Software Engineering – Ian Sommerville
Visual Modeling with Rational Rose 2002 and UML
– Terry Quatrani
Rational Software Architect – Quick start guide
Object Oriented modeling and Design – James
Rambaugh, Michele Blaha, el.,
1
1/4/20
What is Object-Oriented?
Object oriented analysis and design is a bottom-up
way of thinking about problems using models
organized around real-world concepts.
The fundamental building block is the object.
Object combines data structures and behaviors in a
single entity.
What is Object-Oriented?
Organisation of software as a collection of discrete
objects that incorporate both data structures and
behaviors.
This is in contrast to conventional programming in
which data structures and behaviors are loosely
connected.
2
1/4/20
Behavioral Models
Systems have static & dynamic characteristics
¡ Structural models describe the static aspects of the system
¡ Behavioral models describe the dynamics and interactions of the
system and its components
Behavioral models describe how the classes described in
the structural models interact in support of the use cases.
Characteristics of Objects
Identity
¡ The data is quantized into discrete, distinguishable entities
called objects.
¡ ex : wheel of a bike, paragraph of a text, window on work
station, etc
Classification
¡ The objects with same data structure (attributes) and
behaviors (methods) are grouped into a class.
¡ Ex: Bingo is an object, belongs to dog class and animal super
class (Abstract)
3
1/4/20
Characteristics of Objects
Polymorphism
¡ The same behavior may occur differently in different classes.
¡ ex : move operation on a window is differ from move
operation on file, etc
Inheritance
¡ the sharing of attributes and operations among classes based
on hierarchical relationship.
¡ ex: classes can create sub classes
OO Design & Development
Problems are changing but problem-domain remains
Customer requirements may change but business
environment is same
OOAD address problem-domain
Structured methods address problem
Reusability, Modularity, portability, Modifiability
are there
4
1/4/20
What is Object-Oriented Development?
New way of thinking about software based on
abstraction that exist in real world
In this context development refers to the front
portion of the software life cycle: analysis, design,
Implementation
The essence of OO development is the
identification and organisation of application-
domain concepts, rather than their final
representation in a programming language, OO or
not
What is Object-Oriented Development?
OO development approach encourages software
developers to work and think in terms of the
application domain through most of the SE life
cycles.
It is independent of a programming language until
final stage.
It uses for communication & specification
description tools, documentation, interfacing,
programming
5
1/4/20
Basic Principles of Object Orientation
Object Orientation
Encapsulation
Abstraction
Modularity
Hierarchy
What is Abstraction?
Salesperson
Not saying
Which
salesperson –
just a
salesperson
in general!!!
Product
Customer
Manages Complexity
6
1/4/20
What is Encapsulation?
Hide implementation from clients
¡ Clients depend on interface
How does an object encapsulate?
What does it encapsulate?
Improves flexible
What is Modularity?
The breaking up of something complex into
manageable pieces Order
Entry
Order Processing
System Order
Fulfillment
Billing
Manages Complexity
7
1/4/20
What is Hierarchy?
Levels of abstraction Asset
Increasing
abstraction
BankAccount Security RealEstate
Savings Current Stock Bond
Elements at the same level of the hierarchy
Decreasing should be at the same level of abstraction
abstraction
Basic Concepts of Object Orientation
Object
Class
Attribute
Operation
Interface (Polymorphism)
Component
Package
Subsystem
Relationships
8
1/4/20
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
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
9
1/4/20
Representing Objects
An object is represented as rectangles with
underlined names
: Professor
a + b = 10
ProfessorMala
Class Name Only
Professor Mala
ProfessorMala :
Professor Object Name Only
Class and Object Name
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
10
1/4/20
Sample Class
Class
Course
Properties Behavior
Name Add a student
Location Delete a student
a + b = 10
Days offered Get course time table
Credit hours Determine if it is full
Start time
End time
Representing Classes
A class is represented using a compartmented
rectangle
a + b = 10
Professor
Professor Mala
11
1/4/20
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( )
Classes of Objects
How many classes do you see?
12
1/4/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 Geetha Professor Mala
Professor Seetha
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
13
1/4/20
What is an Operation?
CourseOffering
Class
addStudent
deleteStudent
getStartTime
Operation getEndTime
What is Polymorphism?
The ability to hide many different implementations
behind a single interface
Manufacturer B
Manufacturer A Manufacturer C
14
1/4/20
What is an Interface?
Interfaces formalize polymorphism
Interfaces support plug-and-play architectures
Tube
<<interface>>
Shape
Pyramid
Draw
Move
Scale
Rotate Cube
Realization relationship
Interface Representations
Tube
Iconic
Representation
Pyramid
Shape Cube
Canonical Tube
(Class/Stereotype) <<interface>>
Representation Shape
Pyramid
Draw
Move
Scale
Rotate Cube
15
1/4/20
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
¡ A run time components or
OO Principle:
¡ An executable component Encapsulation
Source File <<EXE>> <<DLL>>
Name Executable Component
Name Component Name
Interface
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
16
1/4/20
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
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
17
1/4/20
Relationships
Association
Aggregation
Composition
Dependency
Generalization
Realization
Relationships: Association
Models a semantic connection among classes
Association Name
Professor Works for University
Association
Role Names
Class University
Professor
Employee Employer
18
1/4/20
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
Relationships: Composition
A form of aggregation with strong ownership and
coincident lifetimes
¡ The parts cannot survive the whole/aggregate
Whole Part
Student Schedule
Aggregation
19
1/4/20
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
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
20
1/4/20
Example: Multiplicity and Navigation
Multiplicity
Student 1 0..* Schedule
Navigation
Relationships: Dependency
A relationship between two model elements where a
change in one may cause a change in the other
Client Supplier Component
Class
Package Client Supplier
Dependency
relationship
ClientPackage SupplierPackage
Dependency
relationship
21
1/4/20
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
Example: Single Inheritance
One class inherits from another
Ancestor
Account
balance
name
Superclass number
(parent) Withdraw()
CreateStatement()
Generalization
Relationship
Current Savings
Subclasses Withdraw() GetInterest()
Withdraw()
Descendents
22
1/4/20
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 !
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
23
1/4/20
Example: What Gets Inherited
GroundVehicle
owner Person
Superclass weight
(parent) licenseNumber 0..* 1
register( )
generalization
Car Truck Trailer
Subclass size Tonnage
getTax( )
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
24
1/4/20
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
Class Diagram for the Sales Example
Sale
seller buyer item sold shipping mechanism
Salesperson Customer Product Vehicle
Corporate Individual Truck Train
25
1/4/20
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
Questions?
Next à UML Notations
26