System_Design_1 Flashcards
(5 cards)
What does SOLID stand for?
S - Single Responsibility Principle (SRP) - A class should have only one reason to change O - Open/Closed Principle (OCP) Software entities should be open for extension, but closed for modification
L Liskov Substitution Principle (LSP) - Subtypes must be substitutable for their base types I Interface Segregation Principle (ISP) - Clients should not be forced to depend on interfaces they don’t use
D Dependency Inversion Principle (DIP) - Depend on abstractions, not concrete implementations
What is the Open/Closed Principle?
You should be able to add new behavior without changing existing code.
This is usually achieved through abstraction (interfaces, abstract classes, polymorphism) and design patterns (like Strategy, Decorator, etc.).
Violating OCP is not only about using instanceof or if-else. It’s any time you:
Add new logic by changing existing classes instead of extending them.
Hardcode dependencies instead of injecting abstractions.
Use enum or String to trigger behavior instead of polymorphism.
Tips to follow OCP
Technique | How it Helps
Interfaces & Abstract Classes** | Allow new behavior without touching core code |
| Polymorphism | Replace conditionals with overridden behavior |
| Dependency Injection | Decouple implementations |
| Design Patterns | Strategy, Decorator, Command, State, etc. all support OCP |
What is the pattern below?
var S
Pattern Name: Singleton Pattern (with IIFE)
What it does:
Ensures only one instance of an object is ever created.
Uses an Immediately Invoked Function Expression (IIFE) to encapsulate a private instance (inst).
Provides a public method (getInst) to access that instance.
Which term is not related to OOP?
Encapsulation?
Isomorphism?
Polymorphism?
Inheritance?
❌ Isomorphism
Encapsulation — Key OOP concept: bundling data and methods, controlling access.
Polymorphism — Key OOP concept: objects taking many forms, method overriding/overloading.
Inheritance — Key OOP concept: classes deriving properties and behavior from parent classes.
Isomorphism — Not an OOP term; it’s a concept in mathematics and other fields meaning “structural similarity.”