SOLID principles and design patterns Flashcards

1
Q

What are the 4 main features of OOP?

A
  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are design patters?

A

Not solutions but more principles, ideas or descriptions of how some code should function to implement the ‘pattern’.

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

What are the three common types of design patterns?

A
  1. Creational patterns
  2. Structural patterns
  3. Behavioural patterns
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are creational patterns?

A

Concerned with creating objects as needed for the problem/situation faced.

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

What are structural patterns?

A

Concerned with describing the relationships among objects.

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

What are behavioural patterns?

A

Concerned with communication among objects.

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

What are the SOLID principles?

A
  • Single-responsibility principle
  • Open-closed principle
  • Liskov substitution principle
  • Interface segregation principle
  • Dependency inversion principle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a short definition for Single-responsibility principle?

A

A class should only have a single responsibility.

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

What is a short definition for open-closed princple?

A

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

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

What is a short definition for Liskov substitution principle?

A

Objects should be replaceable with instances of their subtypes without altering the correctness of that program.

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

What is a short definition for interface segregation principle?

A

Many client-specific interfaces are better than one general-purpose interface.

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

What is a short definition for dependency inversion principle?

A

Depend on abstractions and interfaces, not concrete objects

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

What is the explanation for Single-Responsibility Principle?

A

Concerns should be separated. Every class should be focused solely on one activity only, and the only reason to change it should be because that activity changes (excluding bug fixes)

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

Consider this example: You have a single class that is responsible for requesting data from a remote system and generating reports. When might you rewrite the code according to the Single-Responsibility Principle.

A
  • if the remote system changes
  • if the report format changes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Provide an explanation for the Open-Closed principle:

A

Software entities (class, modules, functions) should be open for extension but closed for modification.
Closed in the sense that it has a fixed API others can depend on.
Open in the sense that a component can be extended.

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

Provide an explanation for the Liskov Substitution Principle (LSP)

A

In a subtype relationship, a derived class should be substitutable with any of its base class.

17
Q

Provide an explanation for Interface Segregation Principle:

A

Develop many specific interfaces (virtual classes in C++) for each specific concern rather than grouping them into homogenous blocks.

18
Q

What does the interface segregation principle promote?

A
  • Modularity
  • Reduced coupling
  • Extensibility
19
Q

Provide an explanation for the dependency inversion principle:

A

High level classes do not depend upon low level classes. They depend upon abstractions. Abstractions do not depend upon details; details depend upon abstractions.

20
Q

What is the builder design pattern?

A

A design for constructing complex objects step by step.

21
Q

What does the builder design pattern help?

A

Helps separate construction of an object from its representation.

22
Q

What does the builder pattern do?

A

Designing our code in a certain way to encourage the use of classes. Rather than expose the construction of our complex classes we abstract it.

23
Q

What is the Singleton pattern?

A

The idea that there can only be one instance of class.

24
Q

What SOLID rule does the Singleton pattern violate?

A

The single Responsibility Principle. Singleton instances do something and control their own lifecycle.