Tuesday 13 May 2014

Characteristics of OOPs- 2

                   Characteristics of OOPs- 2


Classes
A class is a group of objects that share common properties and relationships.
For example
Consider a class fruit as shown below


Mango, Apple, Banana, Guava etc are the objects of the class fruit.

Classes are user-defined data types and behave like the built-in types of a programming language. Objects are variables of the type class.

Defining the class doesn’t create any objects, just as the mere existence of a type integer does not create any integer variable.


Data Abstraction

Abstraction refers to the act of representing essential features without including the background details of explanations. Let’s look up the few examples.
1.   In order to drive a car, a person need not know all the parts in it. He can easily drive by using the external interfaces, such as steering wheel, accelerator, brake and clutch. This is abstraction.
2.   A TV user can switch on the TV set and enjoy the various TV program-mes or he/she switch from one channel to another for selecting the desired TV program-me, without knowing its complete technical details.

The advantagesof abstraction are that one can use an object without knowing all its details. This helps the user to use an object with minimum information. i.e.  Just enough information about how to interact through the external interface.
In OOP, the representation of important features (attributes and functions) of an object is done with the help of a class. Class members (both data and functions) may be public or private. The private members of class cannot be accessed from outside the class. However, the public members can be accessed from outside the class.

Therefore, each object of a class will have external interfaces (Public members) through which it can be made use of. There is no need to look into its inner details (Private members). The user needs to know the external interfaces only to make use of an object. The internal details of the objects are hidden which makes them abstract. The technique of hiding internal details in an object is called data abstraction.

Since the classes use the concept of data abstraction, they are also known as Abstract Data Types (ADT).
 




Data Hiding
Access to the private part of an object is restricted in the sense that the functions of the object can only access the data. Thus, the private parts of the objects are not available outside the object and cannot be altered by external changes. This property of an object is called as information hiding or data hiding.


Encapsulation
The wrapping up (or binding) of data and functions (that operate on the data) into a single unit (called class) is known as encapsulation.

Encapsulation is the most fundamental concept of OOP. Thus, the inner parts of the program are sealed or encapsulated to protect from accidental tampering. This feature is not available in procedure oriented languages where the data can be corrupted since it is easily accessible.
  Advantages of encapsulation are given below:
 Data Security: The data is not accidentally corrupted by external world.
It ensures that changes to data and functions of an object can be made without affecting other objects.
Objects are independent of each other. Therefore, each object can be studied properly for better understanding the design.
 


 


The student and library classes are independent of each other. The class student has details about class library. But the object of student class can communicate within the object of library class in case of book requirement by sending a message. The object of library will accordingly respond to the message received.
Relation between encapsulation and Abstraction is given below...






No comments:

Post a Comment