OOP Concepts
Core object-oriented programming concepts with real-world context, code examples in Swift, Kotlin, TypeScript, Python & Java, and practical guidance for every scenario.
Pillars
The four foundations of object-oriented designBundles data and the methods that operate on that data within a single unit, restricting direct access to an object's internal state.
Hides complex implementation details behind a simple, well-defined interface, exposing only what the caller needs.
Allows a class to derive shared state and behavior from a parent class, forming an "is-a" relationship.
Allows objects of different types to be treated through a common interface, with each type providing its own behavior for the same call.
Relationships
How objects relate to and depend on each otherA general relationship where one object uses or interacts with another, without ownership — both objects can exist independently.
A "has-a" relationship where a container holds references to objects that can exist independently of it — a whole-part relationship without ownership.
A strong "has-a" relationship where the part's lifecycle is bound to the whole — when the container is destroyed, so are its parts.
Principles
The SOLID principles for maintainable OO codeA class should have only one reason to change — it should do one thing and do it well.
Software entities should be open for extension but closed for modification — add new behavior without changing existing, tested code.
Subtypes must be substitutable for their base types without altering the correctness of the program.
Clients should not be forced to depend on interfaces or methods they do not use — prefer many small, focused interfaces over one large general-purpose one.
High-level modules should not depend on low-level modules directly — both should depend on abstractions.