Object-oriented programming (OOP) organizes code around objects that bundle data and behavior. These four principles are the core ideas behind clear, maintainable OOP design.
Encapsulation
Keep data and the logic that uses it inside one unit (a class), and hide internal details from the outside. Other code talks to the object through a clear public interface (methods), not by reaching into its fields. That protects internal state from misuse and lets you change how things work inside without breaking callers. In short: bundle data with behavior and expose only what’s needed.
Abstraction
Show only what’s necessary and hide complexity. You define a simple interface (e.g. “start engine,” “send message”) and hide the steps and data structures behind it. Callers depend on the idea (what the object does), not the implementation (how it does it). That reduces coupling and makes the system easier to understand and change. In short: focus on what an object does, not how it does it.
Inheritance
A class can inherit fields and methods from another class (the parent or base). The child class reuses the parent’s code and can add or override behavior. That avoids duplication and builds a hierarchy (e.g. Animal → Dog, Cat). Use inheritance when there is a clear “is-a” relationship; prefer composition (“has-a”) when you only need to reuse behavior without a strict hierarchy. In short: reuse and extend existing types by creating subtypes.
Polymorphism
Different types can be used through the same interface. Code that works with a base type (e.g. Shape) can work with any subtype (e.g. Circle, Square) without knowing the concrete class. The right method runs based on the actual object at runtime. That lets you add new types without changing existing code and write generic logic that works with many implementations. In short: one interface, many forms—call the same method and get the right behavior for each type.
Summary
Encapsulation – Bundle data and behavior, hide internals behind a public interface. Abstraction – Expose what’s needed, hide how it’s done. Inheritance – Reuse and extend types through a parent–child hierarchy. Polymorphism – Use one interface for many types; the correct behavior is chosen at runtime. Together they keep OOP code organized, reusable, and easier to evolve.