Object Oriented Modeling and Design
Object Oriented Modeling and Design
Ordering:
Usually objects on many sides of an association have no explicit order, and can be
considered as a set.
Example 1: Workstation screen containing a number of overlapping windows. The windows
are explicitly ordered, so only the topmost window is visible at any point on the screen.
{Ordered}
Window Screen
Visible-on
{Ordered}
Bank teller Customer
Servers
Home directory
Authorization
Directory
Priority
Privileges
Start session ()
Example 2: Plays-on
Player Team
Negotiated-by
Contract General
Manager
Qualified association:
When an association’s multiplicity is one-to-many, a particular challenge often arises:
lookup.
When an object from one class has to choose a particular object of another class in order to
fulfil a role in an association, the first class has to rely on a specific attribute to find the right
object. That attribute is typically an identifier, such as an ID_NUMBER.
Example: We make reservation at a hotel; the hotel assigns us a confirmation number. If we
call with questions regarding reservation we have to specify confirmation number.
1 Finds *
Person or Reservation
clerk Confirmation number
Qualifier symbol is a small rectangle adjoining the class that does the looking up.
The idea is to effectively reduce a one-to-many multiplicity to a one-to-one multiplicity.
Example 2: A directory contains many files. Within the context of the directory, the filename
specifies a unique file.
Directory File
Filename
0...4Passenger
Drives
R.A’s are represented by drawing an association line from the class rectangle back to the
same class rectangle.
Example 2: A directory may contain many other directories and may optionally be contained
in another directory.
Container Directory
Contents
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 provide a way of viewing a binary association as a traversal from one object to a set of
associated objects.
Example 1: Person and Company
Specifies how Person and Company participate in association “Works-for”. A person
assumes the role of the employee with respect to company; a company assumes the role of
employer w.r.t a person.
Works-for
Person Company
Employee Employer
John TCS
Kiran BOSCH
Smith TCS
A role names are written next to the association line near the class that plays the role.
Role names are necessary for associations between 2 objects of the same class.
Example 2: “Boss” and “Worker” distinguish the 2 employees participating in the
“Manages” association.
Boss Person
Manages
Worker
Example 3: A directory may contain many other directories and may optionally be contained
in another directory. Each directory has exactly one user who is an owner, and many users
who are authorized to use the directory.
Owner Container
User Directory
Authorized user
Contents
Aggregation:
The human is an entity that is obtained by putting together all the organs. This is a classic
example of aggregation.
Aggregation is based on the principle of “A whole is a sum of parts”.
It is used when we want to put create an entity by putting together all the existing entities.
For example hands, legs, face put together form a human.
The process of putting together components to get the required entity is called
“Aggregation”.
Aggregation is a “part-whole” or “a-part-of” relationship in which objects representing the
components of something are associated with an object representing the entire assembly.
Aggregation is a special type of association with some extra semantics.
Example 1: A document consists of many paragraphs, each of which consists of many
sentences.
Aggregation is drawn like association, except a small diamond indicates the assembly end of
the relationships.
Properties of aggregation:
1. Transitivity: if A is part of B and B is part of C then A is part of C.
Example: Carburettor is part of engine, and engine is part of car then carburettor is part
of car.
Car Engine Carburettor
Car Wheel
Microcomputer
Aggregation Vs Association:
Aggregation comes about because an entity consists of several components.
Association on the other hand is the relationship between the entities.
Example 1: An account is an aggregation of customer details, operational instructions,
business rules etc. the customer is not part of the account but has relationship to an account.
Account Customer
1..* Owned by
Works-for
Person
Generally if classes are tightly bound by a whole-part relationship then the relationship can
be termed as aggregation.
The decision to use aggregation or association is not well defined and is a matter of
judgement and is often arbitrary.
Savings Current
Account Account
Example 2: Vehicle
Nature of account
Aggregation Vs Generalization:
Aggregation is not the same thing as generalization.
Aggregation relates instances. Two distinct objects are involved; one of them is a part of the
other.
Generalization relates classes and is a way of structuring the description of a single object.
Both superclass and subclass refer to properties of a single object.
With generalization, an object is simultaneously an instance of the superclass and an
instance of the subclass.
Both generalization and aggregation gives rise to a tree like structure.
An aggregation tree is composed of object instances that are all parts of a composite object;
a generalization tree is composed of classes that describe an object.
Aggregation is often called “a-part-of” relationship; generalization is often called “a-kind-of
“or “is-a” relationship.
Example 1: Lamp
Fluorescent Incandescent
lamp lamp
A lamp is made of a base and a cover and a switch; a lamp is a fluorescent lamp or an
incandescent lamp.
Aggregation is sometimes called an “and-relationship” and generalization an “or-
relationship”.
Recursive Aggregates:
Aggregation can be fixed, variable or recursive.
A fixed aggregate has a fixed structure; the number and types of subparts are predefined.
Example 1: Lamp
A variable aggregate has a finite number of levels, but the number of parts may vary.
Example 2:
A recursive aggregate contains, directly or indirectly an instance of the same kind of the
aggregate; the number of potential levels is unlimited.
Example 3:
Program Blocks
Simple Compound
statements statements
Metadata:
Metadata is a data that describes other data. For example, the definition of a class is
metadata.
Relational database management systems use metadata. A person can define database tables
for storing information. Similarly, a relational DBMS has several metatables that store table
definitions.
Thus a table may store the fact that the capital of India is Delhi, capital of Japan is Tokyo. A
metatable would store the fact that a country has a capital.
Candidate keys:
It is a minimal set of attributes that uniquely identifies an object or link.
By minimal, we mean that you cannot discard an attribute from the candidate key and still
distinguish all objects and links.
A class or association may have one or more candidate keys, each of which may have
different combinations and number of attributes.
An object identifier is always a candidate key for a class. One or more combinations of
related objects are candidate keys for associations.
Multiplicity and candidate keys have nearly same expressive power for binary associations.
Multiplicity also includes the notion of existence dependency – whether an object must
participate in an association or not.
Candidate key is delimited in an object model with braces.
Examples:
1. Many-to-many association: it requires both related objects to uniquely identify each link.
Person
Owns-stock
{Candidate keys: (person, company)}
Company
2. One-to-many association: it has a single candidate keys – the object on the
many end.
Person
Works-for
Company
{Candidate key: (person)}
4. Candidate keys can also be specified even when one or both classes are
optional.
Has-capital
Country Country
[A city may not be a capital at all, but a city is capital of at most one
country]
5. Ternary association: it has one candidate key consisting of all three objects.
No combination of just one or two objects will uniquely identify each link.
Project Language
Person
Abstract classes:
An abstract class is a class that has no direct instances or an abstract class is one that does
not have any objects or more precisely, it is not allowed to have any objects.
An abstract class is only used to inherit from, in that it describes common attributes and
behaviour or operations for other classes.
Example 1: A class hierarchy for vehicles. The Car class is subclass to vehicle, but
superclass to Sports car, Passenger car, and Truck.
Vehicle
Car Boat
Sports car Passenger Truck Sailing boat Motor boat Cargo ship
car
A vehicle class is excellent to capture the commonalities between the car and boat. Vehicle
is an example of abstract class, which does not have any objects, but is used only to inherit
from.
A class can be specified explicitly as abstract by putting the tagged value {abstract} within
the compartment of the class, under the class name shown in example 2.
Example 2:
Vehicle {abstract}
drive ( ) {abstract}
Car Boat
drive ( ) drive ( )
An abstract class normally has abstract operations. An abstract operation is one that has no
implementation method in the class where it is specified; only the signature is shown.
A class that has at least one abstract operation must be an abstract class.
A class that inherits from a class that has one or more abstract operations must implement
those abstract operations (provide methods for them) or itself become an abstract class.
Abstract operations are shown with the property string {abstract} following the operation
signature.
Abstract operations are defined in abstract classes to specify behaviour that all the
subclasses must have.
In example 2, a Vehicle class could have abstract operations to specify that all vehicles must
be able to drive, start, and stop. Thus all classes inheriting from the vehicle must provide
methods for those operations (or themselves become abstract).
Example 3: Class Employee is an abstract class. All employees must be hourly, salaried, or
exempt. Compute pay is an abstract operation of class Employee; its form but not its
implementation is defined. Each subclass must supply a method for its operation.
Employee
Year-to-date earnings
Compute-pay ( )
{abstract}
The origin class of a feature is the topmost defining class. The origin class defines the
protocol of the feature that is the type of an attribute or the number and the type of
arguments and the result type of the operations as well as the semantic intent. Descendent
classes can refine the protocol by further restricting the type or by overriding the
initialization or method code. Descendent classes may not expand or change the protocol.
Concrete classes:
A concrete class is a class that is instantiable; that is it can have direct instances or from
which we can create objects.
A concrete class have implementations for all the operations.
If the Vehicle class (example 2) has specified an abstract operation drive, then both cars and
boats must implement that method. The implementations are different, though.
When someone tells the boat to drive, the propeller moves or if its car then wheel moves.
As shown, the subclass can redefine operations. A redefined operation must have the same
signature (return type, name and parameters) as the superclass.
The operation being redefined can be either abstract (not have an implementation in the
superclass) or concrete (have implementation in the superclass). In both cases, the
redefinition in the subclass will be used for all instances of that class.
New operations, attributes, and association can added to the subclasses. An object of a
subclass may be used in any situation where it is possible to use the superclass objects.
Example 1: A Person class has drives association to the Vehicle class. The Vehicle class is
abstract; that means that the actual objects that the person drives are from the concrete
subclasses Car and Boat. When the person calls (performs) the drive operation, the result
depends on whether the object used in that situation is a car or a boat.
drive ( ) {abstract}
Car Boat
drive ( ) drive ( )
Consists of * position:pos
draw ( ) {abstract}