Basic object oriented features and concepts
Various important features of object oriented programming are:
- Objects and classes
- Message passing
- Dynamic binding
1. Objects and classes: The objects and classes are the main part of the oops programming. The objects can represent a place, a person and much more. The program objects should be like the real world objects. Objects contain data and code to manipulate the data as given by user.
A class is act as a container which contains data and methods. But class does not occupy any space in the memory. But objects contain the space in memory when they are created. And we can make any number of objects to the corresponding class.
2. Encapsulation: encapsulation is a mechanism for wrapping up data and methods to the single unit called class. Doing so the data is not accessible to the outside world and is only accessible to the outside world and is only accessible to the methods that are wrapped in a class. These methods provide the interface between the objects data from direct access is called data hiding.
Encapsulation makes it possible for object to be treated like ‘black boxes’, each performing a specific task without giving any information regarding internal implementation.
e.g: class box
private int length;
private int breadth;
3. Polymorphism: Polymorphism is combination of two words ‘poly’ means many and ‘morph’ means forms. It is the ability to take more than one form. Polymorphism allows one interface to be used for a general class of action.
It basically refers to the ability of giving the same name to methods in different subclasses. The individual methods may implemented by type of argument passed to them. Different methods can be created with the same name but with the different parameters.
4. Inheritance: The most significant advantage of object oriented programming is the reusability of the code. This reusability achieved by a mechanism called inheritance. Inheritance is also refer to as “is-a” relationship.
Inheritance is basically achieved by creating a new class reusing the properties of existing one along with the additional characteristics of the new class.
This method or mechanism of mechanism of driving a new class from another class is called sub class and the existing class from which the sub class is derived is the base class or super class.
5. Abstraction: Abstraction refers to the act of representing essential feature without including the background details or explanation. A very important rule of abstraction is we filter out the common functionality of the objects into an abstract class which acts as the base class for the object. It is the art of concentrating on the essential things and ignoring the non-essential things.
6. Message passing: As people communicate with each other objects can also communicate with one another by the concept of message passing. A message for an object is a request for execution of a procedure.
7. Dynamic binding: Dynamic binding is also achieved in oops programming. Dynamic binding means that the code associated with a given method call is not known until the time of the call at run time.