← Study Notes Programming Fundamentals


Programming Fundamentals

OOP

Organising code into objects that bundle state with the methods acting on it, using abstraction, encapsulation, inheritance and polymorphism. It maps naturally onto domain entities and hides internals behind clean interfaces. The trade-off: deep inheritance hierarchies grow rigid and tightly coupled, so the modern advice is to favour composition over inheritance.


Purpose

Object-oriented programming organises code into objects that bundle state with the methods that act on it, guided by four pillars: abstraction, encapsulation, inheritance and polymorphism. It exists to manage complexity — hiding internals behind small public interfaces so each part of a system can change independently.

When to Use It

It fits domains with clear entities and behaviour — an Order that can cancel(), a User that can verify() — and underpins most mainstream languages and frameworks, from Java and C# to the class layers of Python and TypeScript.

Polymorphism earns its keep when many variants share one contract: payment providers, storage backends, notification channels.

Trade-offs

Deep inheritance hierarchies become rigid and tightly coupled — a change in a base class ripples everywhere — which is why the modern rule is composition over inheritance. Overuse also invites scattered mutable state, the very thing functional style avoids.

Implementation

Keep classes small and single-purpose, expose behaviour rather than raw fields, and depend on interfaces so implementations can be swapped and tested. Prefer injecting collaborators (dependency injection) over constructing them inside, and reserve inheritance for genuine is-a relationships.