Object Oriented Concepts help programmers to translate real life situations[logical] in to computer applications.
The main concepts are given below.
Data abstractionAbstraction refers to the act of representing essential features without including the background details or explanations.
Nutshell:
Expose on a need to know basis.
Example:
In a mobile phone to make a call all we do is to enter the number and press call/ok.
we don't need to know the technology of how it works.
Information HidingThis is a design consideration. All data and internal implementations to be hidden from client view.
Nutshell:
Secrecy needed for data protection from data accessors [clients].
Example:
That is to fortify your defences against any client intrusions on your castle.
Subtle difference between abstraction and hiding.
EncapsulationStoring data and functions in a single unit is encapsulation.
The idea is to combine the data part and the functional part of a single unit.
This is essentially a language facility. Java offers this facility.
Nutshell:
All related items in One place
Example:
It is like storing all your food items in the kitchen so that it helps you with easy access while cooking rather than having a separate store room.
InheritanceInheritance is the process by which objects can acquire the properties of objects of other class. In OOP, inheritance provides reusability, like, adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes.
Nutshell:
Like Father Like Son
Example:
Best example is people inheriting their genes from their predecessors.
PolymorphismPolymorphism means the ability to take more than one form. An operation may exhibit different behaviours in different instances. The behaviour depends on the data types used in the operation. Polymorphism is extensively used in implementing Inheritance.
Nutshell:
One God Several Faces
Example:
A person exhibiting different characteristics while being in different moods.
But still he is the same person.
Advantages of OOPObject-Oriented Programming has the following advantages over conventional approaches:
OOP provides a clear modular structure for programs which makes it good for defining abstract data types where implementation details are hidden and the unit has a clearly defined interface.
OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.
NOTE:
Information hiding is not only confused with encapsulation, it is also often confused with abstraction.
Abstraction is a technique that helps us identify which specific information should be visible, and which information should be hidden. Encapsulation is then the technique for packaging the information in such a way as to hide what should be hidden, and make visible what is intended to be visible.
Next Session:
Classes and Objects.