OOP's Concepts in .Net, Object, Abstraction, Encapsulation, Polymorphism, Inheritance and Aggregation

Object oriented programming (OOP) is an approach to software development in which the structure of the software is based on objects interacting with each other to accomplish a task.This interaction takes the form of messages passing back and forth between the objects. In response to a message, an object can perform an action or method.

 

The Characteristics of OOP:

 

In this section you are going to look at the some fundamental concepts and terms common to all OOP languages.

 

Object: An object is a structure of incorporating the data and procedures for working with data. For example if you want to track the employee’s information in a company, you have to create Emp object which is responsible maintaining and working with the data belongs to all employees in that company.

 

Abstraction: When constructing objects in a OOP application, it is important to filter out extraneous properties of objects, this is called abstraction. In other words abstraction is concept to retain only relevant information to accomplish a task. For example if you want to track normal employee information, just you have to maintain normal employee properties like employee name, id, salary…etc, not Manager properties. You can not instantiate an instance of the abstract class.


Abstract class can contain some abstract methods (which have only method declaration) and some normal methods (which have body also).



Encapsulation:  Encapsulation is the process in which no direct access is granted to the data; instead, it is hidden. If you want to gain access to the data, you have to interact with the object responsible for the data. For example if you want view or update employee information, you would have to work with Emp object.

 

Difference between Abstraction and Encapsulation is, Abstraction is a technique that helps to identify which specific information should be visible and which information should be hidden and Encapsulation is 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.


Polymorphism: Polymorphism is the ability of two different objects to respond to the same request message in their own unique way. You can implement polymorphism concept through overloading. You can implement different methods of an object which has same name but change in number of arguments and type of arguments passing.

 For example you have the employee class which has two methods with the same name empProfile, but one method takes empId as argument another method takes empId and role as arguments. In this situation you pass only empId, then it will call first method which takes only one argument as parameter and if you pass both empId and role, it will call second method which takes two arguments.

 

 

Inheritance: Inheritance is concept of clarify objects in your programs according to common characteristics and function. In other words grouping all common characteristics in one class and all other class has to implement this class to work with those characteristics.

For example, you can define Employee class which has common properties name, id…etc for all employees and managers. Manager class has to inherit this Employee class to define general properties and it may have its own properties also like number of employees under him. So, whenever there is a change for Employee class, it will reflect on Manager class also.


 

Aggregation:  Aggregation is when an object consists of a composite of other objects that work together. For example, your Car object is a composite of the wheel objects, the engine object and so on. In fact, the engine object is a composite of many other objects. There are many examples of aggregation in the world around us. The ability to use aggregation in OOP is a powerful feature that enables you to accurately model and implement business processes in your programs.