Unit - 1 Object Modeling
Unit - 1 Object Modeling
AND DESIGN
CHAPTER- 1
INTRODUCTION & OBJECT MODELING
INTRODUCTION
OBJECT-ORIENTED MODELLING AND DESIGN
An object has:
state - descriptive characteristics
The state of a bank account includes its account number and its
current balance
It means that the same operation (i.e. action or transformation that the object
performs) may behave differently on different classes.
Circle
Draw
Rectangle
Triangle
INHERITANCE
Software life cycle (or software process) - series of identifiable stages that a
software product undergoes during its life time.
Feasibility study
Requirements analysis and specification
Design
Coding
Testing
Maintenance
OBJECT-ORIENTED DEVELOPMENT
Analysis:
Starting with the problem statement the ANALYST builds a model of the real
world situation showing its important properties.
The analyst must work with the requestor to understand the problem, because
problem statements are rarely complete or correct.
The analysis model is a precise abstraction of what the desired system must do,
not how it will be done.
The objects in the model should be application domain concepts and not
computer implementation concepts.
It should not contain implementation decisions.
OBJECT-ORIENTED METHODOLOGY
(OMT)
System design:
The System Designer devise a high level decisions about the overall
architecture.
During system design, the target system is organized into
subsystems based on both the analysis structure and proposed
architecture.
The system designer must decide what performance characteristics
to optimize, choose a strategy of attacking the problem and make
tentative resource allocations.
OBJECT-ORIENTED METHODOLOGY
(OMT)
Object design :
Implementation :
Implementers translate the classes and relationships developed
during class design into particular programming language, database
or hardware.
Programming should be relatively minor and mechanical part of the
development cycle, because all the hard decisions should be made
during design.
During implementation, it is important to follow good software
engineering practice so that traceability to the design is apparent and
so that the system remains flexible and extensible.
THREE MODELS OF OBJECT-ORIENTED
METHODOLOGY
1. Object Model:
Describes basic structure of objects and their relationship
Contains object diagram
Object diagram is a graph whose nodes are object classes (Classes) and whose arcs are relationships
among classes.
2. Dynamic Model:
o Describes the aspects of a system that change over time.
o It specifies and implement control aspects of a system.
o Contains state diagram.
o State diagram is a graph whose nodes are states and whose arcs are transitions.
3. Functional Model:
Describes data value transformation within a system.
Contains data flow diagram.
Data Flow Diagram is a graph whose nodes are processes and whose arcs are data flows.
OBJECT ORIENTED THEMES
Abstraction:
o consist of focusing on the essential, inherent aspect of entity and ignore the
accidental properties
o In system development abstraction means focusing on what an object is and
does, before deciding how it should be implemented.
o During analysis abstraction means dealing only with application domain
concepts, not making design and implementation decisions, before the problem
is understood.
Encapsulation :
o (Information Hiding) separates the external aspects of an object , that are
accessible to other objects from internal implementation details of objects,
which are hidden from the other object.
The object model describes the data structure that the dynamic
and functional models operate on.
The operations in the object model corresponds to the events in the dynamic model and
functions in the functional model.
The dynamic model shows decisions which depend on the object values and which
cause actions that change object values and invoke functions.
The functional model describes functions invoked by the operations in the object
model and actions in the dynamic model.
Functions operate on data values specified by object model
Also shows constraints on object values.
Object Modeling
Objects
Classes
Object diagrams provide a formal graphic notation for modeling objects, classes and
their relationships.
Object diagrams are concise, easy to understand and work well in practice
Types of Object Diagrams:
1. Class Diagram:
1. Is a schema, pattern or template for describing possible instances of data
2. Instance Diagram:
1. Describes how a particular set of objects relate to each other.
2. Instance diagrams are useful for documenting test cases and discussing examples.
Attributes:
Attribute is a data value held by the objects in a class.
Each attribute has a value for each object instance.
An attribute should be a pure data value, not a object.
You need not and should not explicitly list identifiers.
Attributes are listed in the second part of the class box. Each attribute
name may be followed by operational value such as type and default
value.
OBJECT DIAGRAMS
It specifies how many instances of one class may relate to a single instance of an
associated class.
It constraints the number of related objects
Often described as “one” or “many”
Subset of nonnegative integers
Multiplicity value is single interval or may be set of disconnected intervals
OMT symbols : solid ball -> zero or more , Hollow ball -> optional (zero or one)
Intervals: “1”,”1+”,”3-5”, “2,4,18”
Multiplicity depends upon assumptions and how you define the boundaries of a
problem
MULTIPLICITY
Determining the multiplicity often exposes the hidden assumtions built into the
model e.g Person WorksFor Company
Underestimating the multiplicity can restrict the flexibility of an application e.g
person with multiple mobile numbers
Overestimating multiplicity imposes extra overhead and requires the application
to supply the additional information to distinguish among the members of
“many” side e.g boss with multiplicity of “zero or one”, Leader and Project group
LINK AND ASSOCIATION
CONCEPTS
LINKS AND ASSOCIATION
It specifies how many instances of one class may relate to a single instance of an
associated class.
In OMT solid ball -> zero or more
Hollow ball -> optional (zero or one)
Multiplicity depends upon assumptions and how you define the boundaries of a
problem.
Figure: One-to-one association and links
Figure: Many-to-many association and links
TERNARY ASSOCIATION
The ternary association describe the relation among the three classes
The ternary association is an atomic unit and can not be subdivided into binary
associations without losing information.
The OMT symbol for general ternary and n-ary associations is a diamond with
lines connecting to related classes. The name of association is written next to the
diamond.
Example: Person who are programmers use computer languages on projects.
Figure: Ternary association and links
ADVANCED LINK AND ASSOCIATION
CONCEPTS
1. Link Attributes
2. Modeling an Association as Class
3. Role Names
4. Ordering
5. Qualification
6. Aggregartion
LINK ATTRIBUTE
An n-ary association has a role for each end. The role names distinguish the ends
of the association and are necessary if a class participates in an n-ary association
more than once
ORDERING
Objects on “many” side of association may or may not have explicit order
The ordering is an inherent part of the association
An order set of objects on the “many” end of association is indicated by writing
“{ordered}” next to the multiplicity dot for the role.
This is a special kind of constraint
QUALIFICATION
The qualifier is a special attribute that reduces the effective multiplicity of an association.
A qualified association relates two object classes and a qualifier
One to many and many to many associations may be qualified
A qualifier is drawn as a small box on the end of the association line near the class it qualifies
Qualification improves semantic accuracy and increases the visibility of navigation paths
Generalization and inheritance are powerful abstractions for sharing similarities among the
classes while preserving their differences
Generalization is the relationship between a class and one or more refined versions of it.
The class being refined is called the “superclass” and each refined version are called a “subclass”.
Generalization is sometimes called a “is-a” relationship. Each instance of a subclass is an instance
of the superclass.
Generalization and inheritance are transitive across an arbitrary number of levels.
The term ancestor and descendent refer to generalization of classes across multiple levels. An
instance of a subclass is simultaneously an instance of all its ancestor classes.
Each subclass not only inherits all the features of its ancestors but adds its own specific attributes
and operations as well.
The notation for generalization is a triangle connecting a superclass to its subclasses.The
superclass is connected by a line to the apex of the triangle. The subclasses are connected by
lines to a horizontal bar attached to the base of triangle.
Figure 3.23 shows an equipment generalization
GENERALIZATION AND INHERITANCE
GENERALIZATION AND INHERITANCE
The dangling ellipsis in the above figure indicates that there are additional
subclasses that are not shown in the diagram.
A discriminator is an attribute of enumeration type that indicates which
property of an object is being abstracted by a particular generalization
relationship
Only one property should be discriminated at once.
The discriminator is optional part of a generalization relationship
Do not nest subclasses too deeply because they are difficult to understand.
GENERALIZATION AND INHERITANCE
USE OF GENERALIZATION
A subclass may override a superclass feature by defining a feature with the same
name
Reasons for overriding the features
1. Specify the behaviour that depends on the subclass
e.g. display operation for figure. Figure superclass and triangle, rectangle, circle
1. Tighten the specification of a feature e.g ellipse superclass and circle subclass
2. For better performance e.g rotate operation on circle
GROUPING CONSTRUCTS
Module
A module is a logical construct for grouping classes, associations, and
generalizations. It captures one view of a situation.
For example: Let us say, electrical, plumbing, etc. are different views of a building.
An object model consists of one or more modules.
Class names and association names must be unique within a module.
Module names are usually listed at the top of each sheet. The same class may be
referenced in many modules.
GROUPING CONSTRUCTS
Sheet
A sheet is a mechanism for breaking a large object model down into a series of
pages.
A sheet is a single printed page. Each module consists of one or more sheets.
Each sheet has a title and a name or number.
Each association/generalization appears on a single sheet. Classes may appear on
multiple sheets.
ADVANCED OBJECT MODELING
AGGREGATION
Abstract class is a class that has no direct instances but whose descendant
classes have direct instances.
A concert class is a class that is insatiable; that is, it can have direct instances.
A concrete class may have abstract class.
Only concrete classes may be leaf classes in an inheritance tree.
ABSTRACT CLASSES
ABSTRACT CLASSES
ABSTRACT CLASSES
ABSTRACT CLASSES
We can use abstract classes to define the methods that can be inherited
by subclasses.
Alternatively, an abstract class can define the signature for an operation
with out supplying a corresponding method. We call this an abstract
operation.
Abstract operation defines the signature of an operation for which each
concrete subclass must provide its own implementation.
A concrete class may not contain abstract operations, because objects of
the concrete class would have undefined operations.
GENERALIZATION AS EXTENSION AND
RESTRICTION
The inherited features can be renamed in a restriction For example, the inherited
features can be renamed the diameter.
Class membership can be defined in two ways:
o Implicitly by rule
1. A rule defines a condition for membership in class; all object whose values
satisfies the rule belongs to the class
2. Suitable for immutable objects
3. E.g. Polygon, Triangles , ellipses, circles etc.
o Explicitly by enumeration
1. Suitable for objects that can undergo changes and yet remains the same
objects
2. Operations that invalidate class membership constraints must be disallowed
on semantic grounds
OVERRIDING OPERATIONS
Use of inheritance for abstract data types and for sharing the implementations
Overriding is done for the following reasons :
1. Overriding for Extension: new operation adds some behaviour to inherited
operation e.g. draw operation in Window and LabeledWindow
2. Overriding for Restriction: new operation restricts the protocol such as
tightening the type of arguments e.g superclass Set may have the operation
add(object) and subclass IntegerSet have more restrictive operation add(Integer)
3. Overriding for Optimization: implementation can take the advantage of the
constraints imposed by restriction to improve the code for an operation e.g. getMax
operation in IntegerSet and SortedIntegerSet
4. Overriding for Convenience: The new class is made a subclass of existing class
and overrides the method that are inconvenient. This adhoc use of inheritance is
semantically wrong and leads to maintenance problems because there is no inherent
relation between the parent and child classes
RULES FOR INHERITANCE
Multiple inheritance permits a class to have more than one superclass and to
inherit features from all parents.
We can mix information from 2 or more sources.
This is a more complicated from of generalization than single inheritance, which
restricts the class hierarchy to a tree.
The advantage of multiple inheritance is greater power in specifying classes and
an increased opportunity for reuse.
The disadvantage is a loss of conceptual and implementation simplicity.
In principal all kinds of different mixing rules can be defined to resolve the
conflicts among features defined on different paths.
MULTIPLE INHERITANCE- DEFINITION
A class may inherit features from more than one class.
A class with more than one superclass is called a join class.
A feature from the same ancestor class found along more than one path is
inherited only once; it is the same feature.
Conflicts among parallel definitions create ambiguities that must be resolved in
implementation.
Kinds of Multiple Inheritance
1. Multiple Inheritance from overlapping classes
2. Multiple Inheritance from disjoint classes
MULTIPLE INHERITANCE FROM
OVERLAPPING CLASSES
Each generalization should cover single property , e.g, where vehicle can travel
A solid triangle indicated overlapping classes
MULTIPLE INHERITANCE FROM DISJOINT
CLASSES
If a class can be refined on several distinct and independent dimension, then use
multiple generalization
A hollow triangle indicated disjoint classes
ACCIDENTAL MULTIPLE INHERITANCE
An instance of a join class is inherently an instance of all the ancestors of the join
class. For example, an instructor is inherently both faculty and student.
Now consider example a Harvard Professor taking classes at MIT.
This is example of “accidental” multiple inheritance, in which one instance
happens to participate in two overlapping classes.
Best approach is a treat Person as object composed of multiple
UniversityMember objects.This workaround replaces inheritance with delegation
But drawback of this approach is there is loss of identity between the separate
roles
ACCIDENTAL MULTIPLE INHERITANCE
WORKAROUNDS
Real world things may be metadata. There are real world things that describe other real world things.
Examples:
1. A part description in catalogue describes manufactured parts
2. A blueprint describes a house
3. An engineering drawing describe a system
Classes can be considered as objects, but they are metaobjects and not real world objects
Class descriptor objects have features, and they in turn have their own classes which are called
metaclasses
A class attribute describes value common to an entire class of objects rather than data
peculiar to the each instance
A class operation is operation on the class itself e.g create new instance of class, query for
summary information for instances in class
CANDIDATE KEYS
Figure 4.18 shows a ternary association that has one candidate key consisting of
all three objects
Persons who are programmers use computer languages on Projects
CANDIDATE KEYS
Homomorphism most likely to occur for complex applications that deal with
metadata
The homomorphism is essentially just an analogy - special type of relationship
between relationships
Proper use of homomorphism constrain the structure of an object model and
improve the correspondence between the model and the real world.