Object-Oriented Model in OOAD
Object-Oriented Model in OOAD
Object
An object is a real-world element in an objectoriented environment that may have a
physical or a conceptual existence. Each object has −
Objects can be modelled according to the needs of the application. An object may have a
physical existence, like a customer, a car, etc.; or an intangible conceptual existence, like
a project, a process, etc.
Class
A set of attributes for the objects that are to be instantiated from the class.
Generally, different objects of a class have some difference in the values of the
attributes. Attributes are often referred as class data.
A set of operations that portray the behavior of the objects of the class.
Operations are also referred as functions or methods.
Example
Let us consider a simple class, Circle, that represents the geometrical figure circle in a
twodimensional space. The attributes of this class can be identified as follows −
During instantiation, values are assigned for at least some of the attributes. If we create
an object my_circle, we can assign values like x-coord : 2, y-coord : 3, and a : 4 to
depict its state. Now, if the operation scale() is performed on my_circle with a scaling
factor of 2, the value of the variable a will become 8. This operation brings a change in
the state of my_circle, i.e., the object has exhibited certain behavior.
Encapsulation
Encapsulation is the process of binding both attributes and methods together within a
class. Through encapsulation, the internal details of a class can be hidden from outside.
It permits the elements of the class to be accessed from outside only through the
interface provided by the class.
Page 3 of 10
Data Hiding
Typically, a class is designed such that its data (attributes) can be accessed only by its
class methods and insulated from direct outside access. This process of insulating an
objects data is called data hiding or information hiding.
Example
In the class Circle, data hiding can be incorporated by making attributes invisible from
outside the class and adding two more methods to the class for accessing class data,
namely −
Here the private data of the object my_circle cannot be accessed directly by any method
that is not encapsulated within the class Circle. It should instead be accessed through
the methods setValues() and getValues().
Message Passing
Any application requires a number of objects interacting in a harmonious manner.
Objects in a system may communicate with each other using message passing. Suppose
a system has two objects: obj1 and obj2. The object obj1 sends a message to object
obj2, if obj1 wants obj2 to execute one of its methods.
Inheritance
Inheritance is the mechanism that permits new classes to be created out of existing
classes by extending and refining its capabilities. The existing classes are called the base
classes/parent classes/super-classes, and the new classes are called the derived
classes/child classes/subclasses. The subclass can inherit or derive the attributes and
methods of the super-class(es) provided that the super-class allows so. Besides, the
subclass may add its own attributes and methods and may modify any of the super-class
methods. Inheritance defines an is a relationship.
Page 4 of 10
Example
From a class Mammal, a number of classes can be derived such as Human, Cat, Dog,
Cow, etc. Humans, cats, dogs, and cows all have the distinct characteristics of mammals.
In addition, each has its own particular characteristics. It can be said that a cow is a
mammal.
Types of Inheritance
Polymorphism
Polymorphism is originally a Greek word that means the ability to take multiple forms. In
object-oriented paradigm, polymorphism implies using operations in different ways,
depending upon the instance they are operating upon. Polymorphism allows objects with
different internal structures to have a common external interface. Polymorphism is
particularly effective while implementing inheritance.
Example
Let us consider two classes, Circle and Square, each with a method findArea(). Though
the name and purpose of the methods in the classes are same, the internal
Page 6 of 10
implementation, i.e., the procedure of calculating area is different for each class. When
an object of class Circle invokes its findArea() method, the operation finds the area of
the circle without any conflict with the findArea() method of the Square class.
Generalization
Specialization
Link
A link represents a connection through which an object collaborates with other objects.
Rumbaugh has defined it as a physical or conceptual connection between objects.
Through a link, one object may invoke the methods or navigate through another object.
A link depicts the relationship between two or more objects.
Page 7 of 10
Association
Association is a group of links having common structure and common behavior.
Association depicts the relationship between objects of one or more classes. A link can
be defined as an instance of an association.
Degree of an Association
Degree of an association denotes the number of classes involved in a connection. Degree
may be unary, binary, or ternary.
Aggregation or Composition
Aggregation or composition is a relationship among classes by which a class can be
made up of any combination of objects of other classes. It allows objects to be placed
directly within the body of other classes. Aggregation is referred as a partof or hasa
relationship, with the ability to navigate from the whole to its parts. An aggregate object
is an object that is composed of one or more other objects.
Example
In the relationship, a car hasa motor, car is the whole object or the aggregate, and the
motor is a partof the car. Aggregation may denote −
Page 8 of 10
TOP TUTORIALS
Python Tutorial
Java Tutorial
C++ Tutorial
C Programming Tutorial
C# Tutorial
PHP Tutorial
R Tutorial
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
SQL Tutorial
TRENDING TECHNOLOGIES