Abstraction in Object-Oriented Programming
How can we understand abstraction correctly?
Intro
As an interviewer, I always ask the candidate to list 4 characteristics of OOP. Some times, I get confused for the examples they give for abstraction. So I think I need take a deeper look at this important concept.
Rationale
According to Wiki
Abstraction is the process of generalizing concrete details, such as attributes, away from the study of objects and systems to focus attention on details of greater importance.
This definition itself is , well, “abstract”. So I google articles about it on internet and I find some of them are misunderstood.
1. BBC UK definition ( BBC really ???)
Abstraction is the process of filtering out – ignoring - the characteristics of patterns that we don't need in order to concentrate on those that we do. It is also the filtering out of specific details. From this we create a representation (idea) of what we are trying to solve.
This it not true. How do we know a characteristics is really not needed? Maybe it is not necessary at the time we start designing the system but what about the future when everything is scaled up or specs are changed?
For example
class Student{
int age;
string name;
int ID;
}This class by BBC definition is abstract. But there are 2 issues with it
Every class can be abstract without effort. Because we can always pick some traits of an object we want and turn it into a class.
This class is no more than an example of the object Student. It is not a representation and we can not extend it to realize the concept.
Abstraction is the concept of object-oriented programming that “shows” only essential attributes and “hides” unnecessary information. The main purpose of abstraction is hiding the unnecessary details from the users. Abstraction is selecting data from a larger pool to show only relevant details of the object to the user. It helps in reducing programming complexity and efforts
It is correct but still not clarify what is “hide” and “show”, from what point of view that can see a characteristic is “hide” or “show”.
What abstraction really is
Like above definition, abstraction is about hiding the unnecessary information which is “how the object does” and only shows the information of “what the object does”.
It is all about creating an additional layer so that it is more intuitive and easier to use to outer world. In the mean time, it covers all the complicated implementation information.
Take a mobile phone as an example. They use the keyboard, the cover and the screen so that you can use without knowing how the phone connect with each other, how the electronics items work. Without them, you can still operate to make a call but it is way harder and you have to be an engineer to do it.
Types of abstraction
Data abstraction
Data abstraction is used to define essential data, properties that represent the entities. It promotes modularity, extension and code reusability.
Data abstraction is realized through classes. It defines what the object is. Using abstraction and inheritance, you can describe “A is B”.
Process abstraction
Process abstraction refers to hiding the internal operation and only expose the methods that the entities can do and return the expected results.
Process abstraction is realized through interface. It defines what the object can do. Using interface, you can describe “A is capable of doing …”.
Abstraction vs encapsulation
Abstraction is about focusing on the high-level functionalities and hiding the complex implementation details. It deals with "what" an object does.
Encapsulation is about hiding the internal state and requiring all interactions to be performed through an object's methods. It deals with "how" the object's data is accessed and modified.
Conclusion
As software projects grow in size and complexity, the importance of abstraction becomes even more pronounced. By mastering abstraction, developers can build robust and scalable applications that stand the test of time, ensuring that the core logic remains clear and comprehensible even as the system evolves
if you like my ideas, hit button 💙
If you have any feedback, make sure to 💬 comment.
If you find this helpful, let’s 🔁 share it.




