c2cedge
LibraryCS Fundamentals › Ch 19
CS Fundamentals · D — Object-Oriented Programming

OOP Design & SOLID Principles

Good OOP isn't just syntax — it's design. The SOLID principles and a couple of common patterns signal that you write maintainable code.

Test weight: Medium–HighAsked by: Product cos, better service rolesDifficulty: Medium–Hard

Beyond the four pillars, interviewers — especially at product companies — probe whether you can design maintainable systems. The SOLID principles are five guidelines for class design, and a few common design patterns show you know proven solutions to recurring problems.

SOLID in one line each

Single Responsibility: a class has one reason to change. Open/Closed: open to extension, closed to modification. Liskov Substitution: a subclass should be usable wherever its parent is. Interface Segregation: many small interfaces beat one fat one. Dependency Inversion: depend on abstractions, not concrete classes.

A few patterns worth naming

PatternSolves
Singletonexactly one shared instance (e.g. a config)
Factorycreate objects without naming concrete classes
Observernotify many subscribers when state changes
Strategyswap interchangeable algorithms at run time
⚡ The edge
  • You don't need to recite every pattern — but being able to state SOLID and explain one pattern (Singleton or Factory) clearly puts you ahead of most candidates.
  • SOLID's through-line is the same as the four pillars taken seriously: low coupling, high cohesion — each class does one thing well and depends on abstractions.
Worked example
'Explain the Single Responsibility Principle.'
  1. A class should have one, and only one, reason to change — it should do one job.
  2. If a class handles both, say, business logic and file saving, a change to either reason forces edits to the same class.
  3. Splitting responsibilities makes each class smaller, easier to test, and less likely to break when requirements shift.
Worked example
'What is the Singleton pattern and when is it used?'
  1. Singleton ensures a class has exactly one instance and provides a global access point to it.
  2. It's used for shared resources like a configuration object, a logger, or a connection pool.
  3. The caution: overuse creates hidden global state and makes testing harder, so apply it sparingly.
⚠ Watch out
  • SOLID is about maintainability, not performance — frame it as managing change.
  • Liskov Substitution is violated when a subclass can't safely replace its parent (e.g. a Square that breaks Rectangle's behaviour).
  • Patterns are tools, not goals — don't force a pattern where a simple class suffices.
Practice this — take a timed mock →
1,300+ questions, scored, with a weak-area report.
Know who's ready. Not who finished.
HomeLibraryPrivacyTerms