Unit 1_Object Model (3)
Unit 1_Object Model (3)
The object model visualizes the elements in a software application in terms of objects.
In this chapter, we will look into the basic concepts and terminologies of object–oriented
systems.
Class
A class represents a collection of objects having same characteristic properties that
exhibit common behavior. It gives the blueprint or description of the objects that can be
created from it. Creation of an object as a member of a class is called instantiation.
Thus, object is an instance of a class.
The constituents of a class are −
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
two–dimensional space. The attributes of this class can be identified as follows −
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
object’s 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 −
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.
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
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 “part–of” or “has–
a” 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 has–a motor”, car is the whole object or the aggregate, and
the motor is a “part–of” the car. Aggregation may denote −
Physical containment − Example, a computer is composed of monitor, CPU,
mouse, keyboard, and so on.
Conceptual containment − Example, shareholder has–a share.