Bundle data and behavior together into objects that model the real-world things your software cares about — the dominant style of enterprise software for 30+ years.
← Back to FoundationsInstead of "do step A, then step B" you say "here's a Customer; ask it to place an order." The world is modeled as objects sending messages.
Hide internal state behind a public interface. Other code talks to the object through methods, never by poking its fields.
Expose what an object does, hide how. A List has add(); you don't care if it's an array or a linked list inside.
A new class extends an existing one, reusing fields and methods. SavingsAccount extends Account.
One interface, many implementations. Shape.area() works on Circle, Square, Triangle — caller doesn't care which.
Inheritance creates an "is-a" relationship (Dog is an Animal).
Composition creates a "has-a" relationship (Car has an Engine).
Modern advice: favor composition over inheritance — deep inheritance trees become brittle.
| Modifier | Visible to |
|---|---|
| public | Anyone. |
| protected | The class and its subclasses. |
| private | Only the class itself. |
| package / internal | Code in the same package or assembly. |
Singleton, Factory, Builder, Prototype, Abstract Factory.
Adapter, Decorator, Facade, Proxy, Composite, Bridge.
Strategy, Observer, Command, Iterator, State, Template Method.
Repository, Unit of Work, DTO, Dependency Injection.
interface Shape { double area(); } class Circle implements Shape { private final double radius; Circle(double radius) { this.radius = radius; } @Override public double area() { return Math.PI * radius * radius; } } class Square implements Shape { private final double side; Square(double side) { this.side = side; } public double area() { return side * side; } } // Polymorphism in action — one method, many shapes. double totalArea(List<Shape> shapes) { return shapes.stream().mapToDouble(Shape::area).sum(); }
| Language | Style | Notes |
|---|---|---|
| Smalltalk | Pure | Everything is an object; the original. |
| Java | Class-based | The enterprise standard. Strongly typed. |
| C# | Class-based | Microsoft's flagship — modern, multi-paradigm. |
| C++ | Multi-paradigm | Adds OOP to C; multiple inheritance allowed. |
| Python | Multi-paradigm | Classes are first-class; duck typing rules. |
| Ruby | Pure | Everything (numbers included) is an object. |
| Kotlin / Swift | Modern | OOP with strong functional features baked in. |
Banking, insurance, ERP — domains rich in nouns and rules.
Widgets, controls, event handlers map cleanly to objects.
Entities, components, behaviors form natural object hierarchies.
Encapsulation pays compound interest over years of maintenance.