Unit 5: Low-level design: OOP and SOLID
The building blocks of good class design: the four pillars of OOP, composition over inheritance, the five SOLID principles, class diagrams, and the concurrency basics LLD questions expect.
The big picture
Low-level design is about code that's easy to change. SOLID is a set of reasons to split or join classes; patterns (next unit) are proven shapes that follow those reasons. Learn the 'why' here, and the patterns will make sense.
Lessons in this unit
- OOP: the four pillars: Object-oriented programming organises code into objects that bundle data and behaviour. Its four pillars are encapsulation, abstraction, inheritance and polymorphism.
- Composition over inheritance, and interfaces: Composition means building a class out of other objects it has ('has-a'), instead of inheriting from a parent ('is-a').
- SOLID: S — Single Responsibility Principle: A class should have one reason to change: one job.
- SOLID: O — Open/Closed Principle: Code should be open for extension but closed for modification: add new behaviour by adding code, not by editing code that already works.
- SOLID: L — Liskov Substitution Principle: Objects of a subclass must work anywhere the parent class is expected, without breaking the program.
- SOLID: I — Interface Segregation Principle: Clients shouldn't be forced to depend on methods they don't use. Prefer several small, focused interfaces over one big one.
- SOLID: D — Dependency Inversion Principle: High-level code should depend on abstractions, not on concrete low-level details.
- UML class diagrams and relationships: A class diagram shows the classes, their fields and methods, and how they relate to each other.
- Concurrency basics: threads, locks and race conditions: Concurrency is several tasks making progress at the same time. A race condition is a bug where the result depends on the exact timing between them.