Monday, September 10, 2012

Abstraction


Abstraction is the process or result of generalization by reducing the information content of a concept or an observable phenomenon.

Abstraction means to show only the necessary details to the client of the object. 

Examples:
1.  When we switch ON Monitor. Does this matter to us what is happening inside the Monitor? No Right, Important thing for you is weather Monitor is ON or NOT. 


2.  When we change the gear of our vehicle are we really concern about the inner details of our vehicle engine? No but what matter to you is that Gear must get changed that’s it! 


3. Let’s say we have a method "CalculateSalary" in your Employee class, which takes EmployeeId as parameter and returns the salary of the employee for the current month as an integer value. Now if someone wants to use that method. He does not need to care about how Employee object calculates the salary? An only thing he needs to be concern is name of the method, its input parameters and format of resulting member, Right? 

This is abstraction; which show only the details which matter to the user. 


The best thing of abstract is that this decouples the user of the object and its implementation. So now object is easy to understand and maintain also.

No comments: