SOLID Priniples Flashcards

1
Q

What is the Single Responsibility Principle?

A

A class should have only one reason to change. It should have only one job or responsibility.

This principle enhances modularity, maintainability, and testability of code.

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

Why is the Single Responsibility Principle important?

A

Makes code modular, easier to maintain, and easier to test.

A modular codebase allows for easier updates and debugging.

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

What does the Open/Closed Principle state?

A

Software should be open for extension, but closed for modification.

This principle allows for adding new functionality without altering existing code.

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

Why is the Open/Closed Principle beneficial?

A

Reduces the risk of bugs by allowing new functionalities to be added without changing existing code.

It promotes stability in existing code while allowing growth.

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

What is the purpose of the Decorator Pattern?

A

To modify behavior by creating a new class that implements the same interface and calls the new method.

This pattern allows selection of methods at runtime using dependency injection.

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

What does the Liskov Substitution Principle emphasize?

A

Derived classes should be substitutable for their base classes without breaking the application.

This principle ensures consistent behavior across class hierarchies.

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

Why is the Liskov Substitution Principle important?

A

It ensures that child classes behave consistently with their parent classes.

This principle supports polymorphism in object-oriented programming.

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

What is the Interface Segregation Principle?

A

Clients should not be forced to depend on interfaces they don’t use.

This principle encourages splitting bulky interfaces into smaller, more specific ones.

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

Why should interfaces be segregated?

A

Prevents creating bloated interfaces that require implementing unused methods.

Segregation leads to cleaner, more manageable code structures.

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

What does the Dependency Inversion Principle advocate?

A

Depend on abstractions, not concretions/implementation.

This principle promotes the decoupling of high-level and low-level modules.

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

Why is the Dependency Inversion Principle significant?

A

Decouples your code and makes it more flexible and easier to test.

This principle supports better software design by enhancing modularity.

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

What is the singleton design pattern?

A

A class that only has one instance, and provides a global point of access to it

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

What is the advantage of the singleton design patter?

A
  • Guarantees only one instance with a unique identifier
  • When implemented correctly, Thread safe, no multiple threads can create multiple instances
  • Lowers memory usage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are disadvantages of Singleton design pattern?

A
  • Can make unit testing difficult since they introduce a global state
  • If later you need multiple instances significant code changes are required
  • Sub classing can be tricky as constructor is typically private.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly