Object-Oriented Modeling and Design
Object-Oriented Modeling and Design
design
.
Ajay Tripathi 1
Introduction
Itis a new way of thinking about problems
using models based on real world concepts.
The basic construct is object which combines
both data structure and behavior in a single
entity.
Rambaugh presents an object oriented
software development methodology, the
Object Modeling Technique (OMT) which
extends from analysis through design to
implementation.
Ajay Tripathi 2
Analysis model is built to abstract essential
aspects of application domain which contains
objects found in application, their properties
and behavior.
Then design model is made to describe and
optimize the implementation.
Finally the design model is implemented in a
programming language, database or
hardware.
Graphical notation is used for expressing
object-oriented models.
Ajay Tripathi 3
What is object-oriented?
Software is organized as a collection of
discrete objects that incorporate both data
structure and behavior.
In general it includes- identity, classification,
polymorphism and inheritance.
Object Oriented Programming Language
Ajay Tripathi 4
Identity
Identity means that data is organized into
discrete, distinguishable entities called objects.
Objects can be concrete or conceptual.
In real world an object simply exist but within a
programming language each object has a
unique handle by which it can be uniquely
referenced.
The handle can be implemented by address,
array index or unique value of an attribute.
Ajay Tripathi 5
Classification
Ajay Tripathi 6
Polymorphism
Ajay Tripathi 7
Inheritance
Ajay Tripathi 8
Object-oriented development?
The theme is the identification and
organization of application concepts rather
than final representation in a prog. Language.
OOD approach encourages software
developers to work and think in terms of the
application domain through most of the
software engineering life cycle.
It is a conceptual process independent of a
programming language until the final stage.
Ajay Tripathi 9
Object-oriented methodology
Stages-
Analysis
System design
Object design
implementation
Ajay Tripathi 10
3 models
Object model
Dynamic model
Functional model
Ajay Tripathi 11
Object model
Ajay Tripathi 12
Dynamic model
Ajay Tripathi 13
Functional Model
Ajay Tripathi 14
Object-Oriented concepts
Abstraction
Encapsulation
Combining data and behavior
Sharing
Object structure, not Procedure
Structure
Synergy
Ajay Tripathi 15
Abstraction
It consists of focusing on essential aspects of an entity and
ignoring accidental properties.
The goal is to isolate those aspects that are important for some
purpose and suppress those aspects that are unimportant.
Abstraction must always for some purpose because the purpose
determines what is and what is not important.
Many different abstractions of same thing are possible,
depending on the purpose for which they are made.
In building models, one must not search for absolute truth but for
adequacy for some purpose.
A good model captures the crucial aspects of a problem and
omits the others.
Focus on what an object is and does, not how to implement.
Ajay Tripathi 16
Ajay Tripathi 17
Encapsulation
Information hiding
Separating external aspects of an object
which are accessible to other objects,
from the internal implementation details
of the object, which are hidden from
other objects.
The implementation of an object can be
changed without affecting the
applications that use it.
Ajay Tripathi 18
Ajay Tripathi 19
Synergy
Identity,Classification, polymorphism
and inheritance can be used in isolation
but together they complement each
other synergistically.
Ajay Tripathi 20
Advantages of OOD……………
Used in developing Compilers, Graphics, UI,
databases, Object oriented languages, CAD
systems, simulations, etc.
Used to document existing programs that are
ill-structured and difficult to understand.
Not reduces development time; it may take
more time than conventional development
because it is intended to promote future reuse
and reduce downstream errors and
maintenance.
Ajay Tripathi 21
Modeling
A model is an abstraction of something
for the purpose of understanding it
before building it.
The word model has 2 dimensions- a
view of a system ( object, dynamic or
functional) and a stage of development
( analysis, design or implementation)
Ajay Tripathi 22
Purpose –
Testing a physical entity before building
it
Communication with customers
Visualization
Reduction of complexity
Ajay Tripathi 23
Object Modeling
Ajay Tripathi 24
Objects
Ajay Tripathi 27
Object diagram
Ajay Tripathi 28
Class diagram
Ajay Tripathi 29
Instance diagram
Ajay Tripathi 30
Person (Person) (Person) (Person)
Ram Jai
Class Diagram
Instance Diagram
Ajay Tripathi 31
Attribute
Ajay Tripathi 32
Object Modeling Notations
Person (Person) (Person)
Ram Jai
name: string 24 34
age: integer
Ajay Tripathi 33
Operations and Methods
An operation is a function or transformation that
may be applied to or by objects in a class.
All objects in a class share the same operations.
The same operation may apply to many
different classes.
Such an operation is polymorphic i.e. the same
operation takes on different forms in different
classes.
A method is the implementation of an operation
for a class.
Ajay Tripathi 34
Person File
name name
age size
change-job print
change-add
Operations
Ajay Tripathi 35
Links and Association
Links and associations are the means for establishing
relationships among objects and classes.
A link is a physical or conceptual connection between objects.
A link is an instance of an association.
An association describes a group of links with common structure
and semantics.
All the links in an association connect objects from the same
classes.
Association and links often appear as verbs in a problem
statement.
An association describes a set of potential links in the same way
that a class describes a set of potential objects.
Ajay Tripathi 36
Associations are bidirectional.
In real, both directions of traversal are equally
meaningful and refer to same association.
Associations are often implemented in
programming languages as pointers from one
object to another.
A pointer is an attribute in one object that
contains an explicit reference to another
object.
Ajay Tripathi 37
A link shows a relationship between two
or more objects.
All connections among classes should
be modeled as association.
One-to-one association
Many-to-many association
Ternary association
Ajay Tripathi 38
Country Has-capital City
name name Class Diagram
Ajay Tripathi 39
Line intersects Point Class Diagram
name 2+ name
(Line)
L1
(Point)
(Line) P1
L2 Instance Diagram
(Line)
L3 (Point)
P2
(Line)
L4
(Line)
L5
Ajay Tripathi 40
Project Language
Person
(Project) (Language)
MIS .Net
(Person)
Jai
(Project) (Language)
CAD C
Ajay Tripathi 41
Multiplicity
Ajay Tripathi 42
Link attributes
Ajay Tripathi 43
Accessible By
File User
Access permission
Ajay Tripathi 44
boss Person Works-for Company
name Name
ssn address
address
worker Salary
Job-title
manages
Performance rating
Ajay Tripathi 45
Modeling an Association as a Class
Ajay Tripathi 46
Authorized on
User Workstation
Authorization
Priority
Privileges
Start session
Home directory
Directory
Ajay Tripathi 47
Role Names
A role is one end of an association.
A binary association has 2 roles, each of
which may have a role name.
A role name is a name that uniquely identifies
one end of an association.
Roles often appear as nouns in problem
descriptions.
Use of role name is optional.
Role names are necessary for associations
between two objects of the same class.
Ajay Tripathi 48
employee employer
person Works-for company
Employee Employer
Ram TCS
Mohan Wipro
Ajay Tripathi 49
ordering
{ordered}
window screen
Visible-on
Ajay Tripathi 50
Qualification
It relates two classes and a qualifier.
Qualifier is a special attribute that reduces the
effective multiplicity of an association.
One-to-many or many-to-many may be
qualified that can be reduced to one-to-one.
( but not always)
It distinguishes among the set of objects at the
many end of an association.
A qualified association can also be considered
a form of ternary association.
Ajay Tripathi 51
Directory File name File
A qualified association
Ajay Tripathi 52
organization
Company office Person
officer
Ajay Tripathi 53
Aggregation
It is a part-of relationship
It has transitivity property i.e. A is part of
B and B is part of C then A is part of C.
It is anti symmetric i.e. if A is a part of B
then B is not a part of A.
Aggregation is a special form of
association.
Ajay Tripathi 54
document paragraph sentence
Aggregation
Ajay Tripathi 55
Aggregation
Ajay Tripathi 56
Aggregation vs. Association
Ajay Tripathi 57
A company is an aggregation of its
divisions which are in turn aggregations
of their departments; a company is
indirectly an aggregation of departments.
A company is not an aggregation of its
employees since the company and
person are independent objects of equal
structure and status.
Ajay Tripathi 58
company division department
Work for
person
Ajay Tripathi 59
Generalization
Ajay Tripathi 60
Figure
Color
Pos
Thickness
Move
Select
Display
rotate
0D 1D 2D
Ajay Tripathi 61
Aggregation vs. Generalization
Aggregation relates instances.
Two distinct objects are involved; one of them
is a part of the other.
Generalization relates classes.
Aggregation is often called “a part of”
relationship; generalization is often called “a
kind-of” or “is-a” relationship.
Aggregation is sometimes called an “and
relationship” and generalization refers to “or
relationship”
Ajay Tripathi 62
lamp
fluorescent incandescent
Ajay Tripathi 63
Aggregation can be fixed, variable or
recursive.
A fixed aggregate has a fixed structure;
the number and types of sub parts are
predefined e.g. lamp.
A variable aggregation has a finite
number of levels but number of parts
may vary e.g. company.
Ajay Tripathi 64
A recursive aggregation contains directly
or indirectly an instance of the same kind
of aggregate; the number of potential
levels is unlimited e.g. computer
program.
Ajay Tripathi 65
program
Compound Simple
statement statement
Simple Statement:
x=i;
Block(combination of more than one simple statements):
++i;
x=i;
Compound Statement(single statement combines work of multiple
statement optionally blocks):
x=++i;
Ajay Tripathi 66
Propagation of operations
Ajay Tripathi 67
A person owns multiple documents.
Each document is composed of
paragraphs that are in turn composed of
characters. The copy operation
propagates from documents to
paragraphs to characters. Copying a
paragraph copies all the characters in it.
The operation does not propagate in
reverse direction.
Ajay Tripathi 68
Propagation can be possible for save,
destroy, print and lock.
Propagation of operations
Ajay Tripathi 69
Abstract classes
An abstract class is a class that has no
direct instances but whose descendent
classes have direct instances.
A concrete class is a class that is
instantiable i.e. it can have direct
instances.
A concrete class may have abstract
subclasses but they must have concrete
descendents.
Ajay Tripathi 70
onlyconcrete classes may be leaf
classes in the inheritance tree.
Ajay Tripathi 71
Abstract & concrete class
subclass subclass
1+ class
1+
Has subclasses
Has subclasses
Ajay Tripathi 72
Abstract classes organize features common to
several classes
Abstract classes are frequently used to define
methods to be inherited by subclasses.
An abstract class can define methods to be
inherited by subclasses.
An abstract operation defines the form of an
operation for which each concrete subclass
must provide its own implementation.
Ajay Tripathi 73
Abstract class & abstract operation
Employee
Earning
Pay {abstract}
Ajay Tripathi 74
Overriding operations
Ajay Tripathi 75
Extension
The new operation is same as inherited except it adds some
behavior usually affecting new attributes of the subclass.
Restriction
The new operation restricts the inherited.
Optimization
The new method must have the same external protocol
(prototype) and results as the old one but its internal
representation and algorithm may differ completely.
Convenience
The new class is made a subclass of the existing class and
overrides the methods that are inconvenient.
Ajay Tripathi 76
Multiple inheritance
Itpermits to have more than one super class
and to inherit features from all parents.
A class with more than one super class is
called a join class.
A feature from the ancestor class found along
more than one path is inherited only once.
Conflicts among parallel definitions create
ambiguities that must be resolved in
implementation.
Ajay Tripathi 77
vehicle
Ajay Tripathi 78
A hollow triangle indicates disjoint
subclasses while a solid triangle
indicates overlapping subclasses.
Ajay Tripathi 79
Metadata
Ajay Tripathi 80
A class describes a set of instances of a
given form.
Instantiation relates a class to its
instances.
The dotted arrows connect the instances
to the class.
It is also useful for documenting
examples and test cases.
Ajay Tripathi 81
(Person)
Name=ABC
Age=40
Weight=40
Person
Name
Age
weight
(Person)
Name=XYZ
Age=29
Weight=70
Ajay Tripathi 82
Class descriptors
Classes are meta objects and not real world objects.
Class descriptors have features and they have their
own classes which are called meta classes.
A class attribute describes a value common to an
entire class of objects rather than data particular to
each instance.
Class attributes are useful for storing default
information for creating new objects or summary
information about instances of the class.
A class operation is an operation on the class itself.
The most common is to create new instances.
Operations on class structure are class operations.
Ajay Tripathi 83
Class descriptors
Window
Size:rectangle
Visibility:boolean
Default_size:rectangle
Display
New_window
Highest_priority_window
Ajay Tripathi 84
Candidate keys
A candidate key is a minimal set of
attributes that uniquely identifies an
object or link.
A class may have one or more candidate
keys each of which may have different
combinations and numbers of attributes.
Each candidate key constrains the
instances in a class.
Notation is {}
Ajay Tripathi 85
constraints
These are functional relation between
entities of an object model.
Entity includes objects, classes,
attributes, links and associations.
A constraint restricts the values that
entities can assume.
Simple constraints may be placed in
object models and complex may be in
functional model.
Ajay Tripathi 86
Window
boss
Employee Length
width
salary
Constraints on objects
Ajay Tripathi 87
General constraints
Ajay Tripathi 88
Derived objects, links and attributes
Ajay Tripathi 89
Homomorphism
A mapping between mathematical structures of the same type
(eg groups or rings) that preserves the structure.
similarity of form
Homos = same & morphe = structure
E.g. in a parts catalog for a automobile, a catalog item may
contain other catalog items.
Each catalog item is specified by a model number that
corresponds to number of individual manufactured items, each
with its own serial number.
The individual items are also composed of sub items.
The structure of each item’s parts has the same form as the
catalog item’s parts.
Thus the “contains” aggregation on catalog items is a
homomorphism of the “contains” aggregation on physical items.
Ajay Tripathi 90
Homomorphism
catalogItem Item
Model# Sl#
Describes
Ajay Tripathi 91
In general, a homomorphism involves 4
relationships among 4 classes.
The homomorphism maps links of one general
association {u} into links of another general
association {t} as a many-to-one mapping.
Two instantiation relationships map elements
of one class into another:
r is a many-to-one mapping from class B to A and
s is a many-to-one mapping from class D to C.
Ajay Tripathi 92
r
A B
t u
{u ( b, d)=>t ( b.r, d.s ) }
C D
s
General Homomorphism
Ajay Tripathi 93
In general where t is on a single class
and u is on a single class then A=C, B=D
and r=s.
Homomorphism is a special type of
relationship between relationships.
Ajay Tripathi 94
Dynamic Modeling
First examine the system at a single moment of time.
Then examine changes to objects and their
relationships over time.
Those aspects of a system that are concerned with
time and changes are dynamic model, in contrast with
static or object model.
Control is the aspect of a system that describes the
sequences of operations that occur in response to
external stimuli without considering what the operation
do, what they operate on, and how they are
implemented.
Ajay Tripathi 95
concepts
Ajay Tripathi 96
Events
Itis something that happens at a point in time
One event may logically precede or follow
another or the two events may be unrelated.
The two events are casually related.
The two events are casually unrelated are said
to be concurrent i.e. they have no effect on
each other.
In modeling a system we do not establish an
ordering between concurrent events because
they can occur at any order.
Ajay Tripathi 97
An event is a one-way transmission of
information from one object to another.
In real world, all objects exist
concurrently.
An object sending an event to another
object may expect a reply but the reply is
a separate event under the control of the
second object which may or may not
choose to send it.
Ajay Tripathi 98
Every event is a unique occurrence, but we group
them into event classes and give each event class a
name to indicate common structure and behavior.
This structure is hierarchical as class structure.
E.g. flight 123 departs from Delhi and flight 321
departs from Rome are instances of event class
airplane flight departs having attributes airline flight no,
city.
The time at which an event occurs is an implicit
attribute of all events.
Ajay Tripathi 99
An event conveys information from one
object to another.
Some classes of events may be simply
signals that something has occurred
while other convey data values i.e.
attributes.
Showing attributes is optional.
Ignition
Turn key to
start[Transmission
in Neutral] Released Key
off starting on
Push N Push F
Forward
data. actorName
Data store -> objects that store data
passively.
Data_storeName
Information/operation Information received from
that modify stored data stored data
Max temp
Readings
Min temp
Account
balance
withdrawl
Customer -
Double headed arrow indicates that balance is both an i/p and o/p of
Subtract operation.
Item_name
cost Price list
account
Create account Bank
Name, deposit
Customer Account
account
verify
password balance
Password
OK
amount
customer update
cash
Equations
Decisions tables
Actions
Activities