System_Design_1 Flashcards

(5 cards)

1
Q

What does SOLID stand for?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Open/Closed Principle?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Tips to follow OCP

A

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 |

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the pattern below?
var S

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which term is not related to OOP?
Encapsulation?
Isomorphism?
Polymorphism?
Inheritance?

A

❌ 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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly