What is Abstraction in Object Oriented Programming?
Abstraction can be formally defined as the representation of an object including the specification of that object in a certain context.Abstraction is a powerful means to tackle the complexity of programming by wrapping up and thus reducing the complexity of complex operations.
Abstraction is used in OOP(Object Oriented Programming) Languages like Java,C++ etc.These OOP Languages employ an abstract entity called class from which instance of that class called object can be created.Data and Code are Binded together in a syntactic container called Object.
These statements can be little confusing for beginner's so read the rest of the post to get a better view of abstraction.
The concept of abstraction is a little confusing of beginner's.
To understand the concept of abstraction easily consider a cactus which has lots of spines placed in box.You can easily carry the box without knowing that a cactus is in it.But it is difficult to carry the cactus with bare hands.Thus Abstraction serves as a box to wrap up the complexities.
In programming subprograms are examples of abstractions,as they can be used to perform a function without knowing the internal details.eg: a function named add(int a,int b) can be used to add two integers and produce a result by simply using the code add(1,2) in the program.The internal details of the function that performs addition is not known to the programmer or to the main program.These details are abstracted and this provides a higher level view.
Abstraction simplifies programming as the programmer needs to focus only on the task he has to perform rather that the internal details of the program.Abstraction are provided in Libraries(.dll) for different operations.
Abstraction is implemented commonly in programming languages by using an data type called class.Objects are Instances of a class
eg:Car is a class Audi,Mercedes etc are Objects of the class named car
Each Object is an a clone of the an abstraction(class),it posses all the traits of class eg:Mercedes and Audi are two brands of cars but they posses all the characters of a the main class car.Thus they are Objects created from the Abstraction Car.The term Car is used to Abstract or wrap up the internal details like engine,wheels,brakes etc in a single container named car.
Data Hiding is a Concept of Abstraction by which the Code and the Data in an Object(Instance of an Abstract Data type usually referred to as class) is hidden from the external entities.