Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views8 pages

Unit 4 OO Concepts and Principles

Uploaded by

shraddhavinod1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views8 pages

Unit 4 OO Concepts and Principles

Uploaded by

shraddhavinod1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

4.

Object Oriented Concepts and Principles


An Object orientation is a technique for system modeling by considering object as a basic building block.
System modeling helps the analyst to understand the functionality of the system.

An Object is an instance of a class. All the instances/objects have same state and behavior in a given
class.

Example: If Student is a class, then specific student from that class can be the object/instance of that
class.

In an Object-Oriented environment:

1. Software is a collection of discrete objects that encapsulate their data as well as the functionality to
model real-world objects.

2. An object-orientation yields important benefits to the practice of software construction.

3. Each object has attributes (data) and methods (functions).

4. Objects are grouped into classes. In object-oriented terms, we discover and describe the classes
involved in the problem domain.
Principles of Object-Orientation (00):

1. Abstraction: It is the process which allows us to focus on the most important aspects overlooking less
important details.

2.Modularity: It allows us to break-up complex, critical systems into small, self-contained parts that can
be managed independently.

3. Hierarchy: It is a tree-like structure and used to order the abstraction. This is also known as
Inheritance.

There are different types of inheritance,

(i) Single Inheritance

(ii) Multiple Inheritance

(iii) Multilevel Inheritance

(iv) Hybrid Inheritance

4. Encapsulation: It mainly separates implementation from users or clients.

5. Polymorphism: Polymorphism means taking more than one form. For example: In the programming,
we can use operator for performing addition of two numbers and also it is used for concatenation of
two strings.

4.1.1 Reasons to use Object-Orientation

1. Higher level of abstraction: The object-oriented approach or technique supports abstraction at the
object level) Since objects encapsulate both data (attributes) and functions (methods), they work at a
higher level of abstraction

2. Continuous transition among different phases of software development: The traditional approach or
technique to software development requires different styles and methodologies for each step of the
process) Moving from one phase to another requires a complex transition of perspective between
models that can be in different worlds.

3. Encouragement of good programming techniques: A class in an object-oriented system carefully


describes between its interfaces, the routines and attributes within a class are held together tightly in a
properly designed system, the classes will be grouped into subsystems but remain independent;
therefore, changing one class has no impact on other classes.

4. Promotion of reusability: Objects are reusable because they are modeled directly out of a real-world
problem domain
5. Easy to adapt and maintain:The systems are easier to adapt to changing requirements, easier to
maintain, more robust It promotes greater design and code reuse.

6. Better model for problem domain: Object-oriented methods enable to create sets of objects that
work together to produce better software models than similar systems produced by traditional
techniques.

4.1.2 Object-Orientation Terminology

Table 4.1 lists some common terms used in Object Orientation (00):

Terms OO Terminology
Object Objects are separate, distinguish and basic run-time entities.

Classes A class is a collection of objects of similar type.

Attribute It is a small piece of information like color, height etc., that describes one
characteristic of an object.

Field It is a named value inside an object.

Operation It is a piece of code belonging to an object.

Method It is a synonym for operation.

Instance An object is an instance of a class

Message It is a request sent from one object to another.

Invocation The carrying out of an operation in response to a message.

Execution It is a synonym for invocation.

Association It is a direct or indirect connection between two objects.

Aggregation It is a strong association implying some kind of part of the whole


hierarchy.

Composition It is a strong aggregation where the part is inside exactly one whole The
part may also be created and destroyed by the whole.

Interface It is a set of messages understood by an object.

Protocol It is an agreed way of passing messages over a network.

Behavior It is a collective term for all of an object's operation.


4.1.3 Object

Object is the basic unit of object-orientation approach.

An object is a real-world element in an object-oriented environment that may have physical or a


conceptual existence.

An object is a piece of structured data in a running software system.

Object can be defined technically as "a combination of data and their associated functions.

Any real-world thing can be treated as an object in the OO as shown

Eg. A Person, A House, A Fruit, A Car

Object and Operation:

Operations are the methods that abstract services of objects. An operation is a function that may be
applied to or by object in a class.

An example of information which we want to save for each object is name, class, percentage and so on.
To access the saved information or to change the saved information, define a set of operations like
accept, display etc.

4.1.4 Classes and Instances:

A class is defined as "a user-defined data type which contains the entire set of similar data and the
functions that the objects possess".

OR Class is defined as "an abstract data type characterized by a set of properties (attributes and
functions) common to its objects".
Instance:
An instance of a class is an actual object of that class. In other words, an object is an instance or
occurrence of a class

The class is the general, abstract representation of an object, and an instance is its concrete
representation.

The objects of a class are also known as the instances or the variables of that class and the process of
creating objects from a class is known as Instantiation.

We can thus define a class Tree and each object that represents a tree becomes an instance of this class.
In Fig. 4.5 we can describe a class Tree where Palm Tree, Mango Tree, Tamarind Tree and Eucalyptus
Tree are instances of this class.

The behavior of the instance and its information structure are, thus defined by its class. Each instance
also has a unique identity i.e., name.

A Tree instance and a Tree object are the same thing.


4.1.5 Polymorphism:
Polymorphism is a Greek term in which poly means "many" and morph means "form". It means the
ability to take more than one form.

Polymorphism means different instances can be associated and these instances can belong to different
classes.

Polymorphism is a very important characteristic for modeling. It is a strong tool for developing flexible
systems. If we add an object of a new class, this modification will affect only the new object and not
those sending messages to it.

Grady Booch defines Polymorphism as "the relationship of objects of many different classes by some
common super class; thus, any of the objects designated by this name is able to respond to some
common set of operations in a different way".

Fig. 4.6 shows an example of polymorphism. In this fig., Shape is a class which contain Draw() method,
which takes many forms like Draw (circle), Draw (rectangle) etc.

4.1.6 Inheritance:
The process by which objects of one class acquire the properties of objects of another class is called as
Inheritance.

Inheritance is the process of forming a new class from an existing class or base class The base class is
also known as Parent Class or Super Class.

The new class that is formed is called derived class. Derived class is also known Child Class or Subclass.

Inheritance helps in reducing the overall code size of the program which is Important concept in Object
Oriented Programming.
In Fig. 4.7, the Santro and Accent are a part of the class Hyundai which is again parte the class Car and
Car is the part of the class Vehicle. That means Vehicle class is the parent class.

Vehicle

Car

Hyundai

Santro Accent

Fig. 4.7: Example of Inheritance

There are five types of inheritance. Let us see details each of them.

1. Single Inheritance: A derived class with only one base class is called 'Single Inheritance'. In Fig. 4.8 (a),
A is a base class and B is a derived class.

inhents

Fig. 4.8 (a): Single Inheritance

2.Multiple Inheritance: A derived class with more than one base class is called Multiple Inheritance. In
Fig. 4.8 (b), class A and class B are base classes and class C is a derived class.

A B

Fig. 4.8 (b): Multiple Inheritance


3. Multilevel Inheritance: When a new class is derived from another derived class, it is called as
Multilevel Inheritance. We can inherit new classes until any level.

A Base class

B Derived class

Base class

C Derived class

Fig. 4.8 (c): Multilevel inheritance

In Fig. 4.8 (c), A is a base class, B is derived from class A. class B is a derived class and play role of base
class from which the class C is derived.

4. Hierarchical Inheritance: Any number of new classes can be derived from a single base class. It is
called as Hierarchical Inheritance.

B C D

Fig. 4.8 (d): Hierarchical Inheritance

In Fig. 4.8 (d), classes B, C and D are derived from the single base class A.

5. Hybrid Inheritance: Two or more types of inheritances are combined to design a program. Class A is a
base class, class B is derived from A and C is derived from base classes B and D. Two types of
inheritances are combined in below inheritance

example: (1) Single, (2) Multiple.

B D

Fig. 4.8 (e): Hybrid Inheritance

You might also like