Object oriented programming

In structure programming languages like C, we define data structures (e.g. arrays, structures etc) and provide functions that inspect or change the data form any place in the program. So when program grows, then it become very difficult to manage such programs.

OOP reduces dependencies between different parts of a program. In OOP, on object contains the data as well as method that will manipulate the data, i.e. everything (data and operations) is encapsulated and at one place rather than being spreadout throughout the program.

In OOP we have Classes and Objects. A class can be considered as a blueprint for objects, which means all objects which are derived from the one class will all be same. objects are also known as instance of a class. For example, "Vehicle" is a class, and "Car", "Motor-Cycle", "Bus" are objects of "Vehicle" class. In out example, Vehicle class will define, how a vehicle will start, how the vehicle will look, whats his maximum speed etc. We can also say class is a design and object is a creation from the design.

Encapsulation is the mechanism that bind the data and the functionality(code) together, disallowing misuse of the data and hiding the internal implementation of the class. Encapsulation restricts the access to some of the object's components.

Inheritance is a process of creating new classes calle derived classes from existing or base classes. The derived class inherits all the capabilities of the base class and can either refine some of its features or add totally new features of its own. Using inheritance we can extend the capability of an entity.

public class A
	public: int i;
	public: void print()
		cout<< "print A";

public class B : public A
	public: int j; //Here class B object can also access A's variable i and A' function print

Polymorphism means the ability to assume several forms. In OOP context this refers to the ability of an entity to refer to objects of various classes at runtime.

In CPP, ew have 3 ways to achieve polymorphism

1. Operator overloading
2. Function overloading
3. Virtual functions

Interfaces in OOP is a way to define a contract of the actions that an object can do. Using interfaces, we can seperate the implementation from the contract, which gives us the flexibility of changing the implementation. One of the very common example of interfaces is web services.

abstraction tells user everything that they may want to know about an objct and nothing else. It indicates what data can an object hold and what functions can it perform on the data. How these functions are performed is abstracted away. Abstraction is very important to lets the user use an object in a safe and predictable manner.
Add Comments :