Abstraction is about showing what is necessary to the client
Encapsulation is about hiding the complexity
Key Differences
- Abstraction is about to show the only necessary, Encapsulation is about hiding complexity
- Abstraction is focusing on what to be done, Encapsulation is focusing on how it can be done.
- Abstraction solves problems at the design level while Encapsulation solves problems at the implementation level
- Abstraction can be achieved using Interface or Abstract class, Encapsulation is achieved through Access Modifiers (Private, Public, Protected, etc.)
- Abstraction is to be achieved during the design level, while Encapsulation is achieved at the implementation level.
Importance of Abstraction
- Abstraction imposes simplicity in the code
- It hides the irrelevant details
- Programmed can be partitioned into a different level and helps decouple the architecture
- Provides flexibility across different types of objects
Importance of Encapsulation
- Makes code more manageable and easy to change with new requirements
- Makes coding easier by hiding the complexity to the client
- This makes unit testing easy
- It helps to change part of code rather than changing everything
- Makes code more readable and understandable to the client what it offers