SOLID Principles Flashcards

1
Q

SOLID - S

A

Single Responsibility Principle

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

Main idea of Single Responsibility Principle

A

A class should have just one reason to change.

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

SOLID - O

A

Open / Closed Principle

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

Main idea of Open / Closed Principle

A

Classes should be open for extension but closed for modification.

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

SOLID - L

A

Liskov Substitution Principle

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

Main idea of Liskov Substitution Principle

A

When extending a class, remember that you should be
able to pass objects of the subclass in place of objects of
the parent class without breaking the client code.

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

What means Liskov Substistution Principle

A

This means that the subclass should remain compatible with
the behavior of the superclass. When overriding a method,
extend the base behavior rather than replacing it with some-
thing else entirely.

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

What Liskov Substitution Principle states about method parameters

A

Parameter types in a method of a subclass should match or be
more abstract than parameter types in the method of the super-
class

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

What Liskov Substitution Princliple states about method return types

A

The return type in a method of a subclass should match or be
a subtype of the return type in the method of the superclass

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

What Liskov Substitution Principle states about throwning exceptions

A

A method in a subclass shouldn’t throw types of exceptions
which the base method isn’t expected to throw

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

What Liskov Substitution Principle states about pre-conditions

A

A subclass shouldn’t strengthen pre-conditions

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

What Liskov Substitution Principle states about post-conditions

A

A subclass shouldn’t weaken post-conditions

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

What Liskov Substitution Principle states about invariants

A

Invariants of a superclass must be preserved

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

What Liskov Substitution Principle states about private fields

A

A subclass shouldn’t change values of private fields of the
superclass

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

SOLID - I

A

Interface Segregation Principle

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

Main idea of Inteface Segregation Principle

A

Clients shouldn’t be forced to depend on methods they do not use (interface should be as narrow as possible)

17
Q

SOLID - D

A

Dependency Inversion Principle

18
Q

Main idea of Dependency Inversion Principle

A

High-level classes shouldn’t depend on low-level class-es. Both should depend on abstractions. Abstractions
shouldn’t depend on details. Details should depend on abstractions.

19
Q

What is low-level class?

A

Implement basic operations such as working with a disk, transferring data over a network, connecting to a
database

20
Q

What is high-level class?

A

Contain complex business logic that directs low-level classes to do something

21
Q

What is an object invariants

A

Invariants are conditions in which an object makes sense. They can be defined explicitly in the form of interface contracts or a set of assertions within methods, they could also be implied by certain unit tests and expectations of the client code.
For example, invariants of a cat are having four legs, a tail, ability to meow.