SOLID Flashcards

1
Q

What are the solid principles?

A

In software engineering, SOLID is a mnemonic acronym for five design principles intended to make object-oriented designs more understandable, flexible, and maintainable.

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

Describe the Single Responsibility Principle (SRP)

A

A class should have only one reason to change.

Responsibilities should be segregated to reduce coupling.

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

Describe the Open/Closed Principle (OCP)

A

Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification.

Concrete classes violate OCP. Instead use interfaces or abstract base classes. Consider the Strategy or Template design pattern. New derivatives/sub-types can be added without breaking OCP.

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

Describe the Liskov Substitution Principle (LSP)

A

An object of a superclass should be replaceable by objects of its subclasses

Defined by Barbara Liskov in 1988.

Simply put, the Liskov Substitution Principle (LSP) states that objects of a superclass should be replaceable with objects of its subclasses without breaking the application. In other words, what we want is to have the objects of our subclasses behaving the same way as the objects of our superclass.

Example violation would be referencing derived types in a base class.

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

Describe the Dependency-Inversion Principle (DIP)

A

A. High-level modules should not depend on low-level modules. Both should depend on abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions.

Inversion of control (IOC) is a technique you can use to comply with DIP.

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

Describe the Interface Segregation Principle (ISP)

A

The interface segregation principle states that no code should be forced to depend on methods it does not use. ISP splits interfaces that are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them.

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