Abstraction in OOP is the principle of exposing only the essential features of an object to the outside world while hiding the complex implementation details. It is achieved through abstract classes and interfaces, which define a contract specifying what methods a class must implement without dictating how they are implemented. Abstraction reduces complexity for the programmer using the class and allows internal implementations to change without affecting dependent code.
| Feature | Abstract Class | Interface |
|---|---|---|
| Can have constructor? | Yes | No |
| Can have concrete methods? | Yes | Yes (default methods in Java 8+) |
| Multiple inheritance? | No (single class only) | Yes (multiple interfaces) |
| Access modifiers on methods? | Any | Public only (implicitly) |
| Use case | Partial implementation shared | Pure contract / capability |
| Example (Java) | abstract class Shape | interface Drawable |
Wikimedia Commons, CC BY-SA
Encapsulation is the OOP principle of bundling an object's data (attributes) and the methods that operate on that data into a single unit (a class), while restricting direct external access to the internal state. By declaring attributes as private and exposing them only through public getter and setter methods, encapsulation enforces data integrity and hides implementation details. This protects objects from unintended interference and simplifies maintenance since internal changes do not affect external code.
An interface in OOP is a fully abstract type that defines a set of method signatures (a contract) that any implementing class must fulfil, without specifying how those methods work. Interfaces enable multiple inheritance of type in languages like Java and C#, allowing a class to implement several interfaces simultaneously. They promote loose coupling in software design by allowing different classes to be used interchangeably when they implement the same interface.
Object-Oriented Programming (OOP) is a programming paradigm that organises software design around data, called objects, rather than functions and logic. Each object encapsulates data (attributes) and behaviour (methods), and objects interact with one another to build complex systems. The four core principles of OOP — encapsulation, inheritance, polymorphism, and abstraction — promote code reusability, modularity, and maintainability.
From Latin "abstractus", past participle of "abstrahere" meaning "to draw away". In philosophy, abstraction involves removing specific details to consider general properties. The concept was applied to programming by Dijkstra and Hoare in the 1970s in discussions of structured programming and modular design.