SOLID Principles Design Patterns and Principles Part 3 Flashcards

1
Q

is a mnemonic for five design principles intended to make
software designs more understandable, flexible and maintainable.

A

SOLID

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

introduced them in the book Agile Software Development, Principles, Patterns, and Practices

A

Robert Martin

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

● A class should have just one reason to change.
● The main goal of this principle is reducing complexity

A

Single Responsibility Principle

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

● Classes should be open for extension but closed for
modification.
● The main idea of this principle is to keep existing code
from breaking when implementing new features.

A

Open/Closed Principle

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

A class is __ if you can extend it, produce a subclass
and do whatever you want with it add new methods
or fields, override base behavior, etc.

A

open

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

A class is __ (or complete ) if it’s 100% ready to be
used by other classes its interface is clearly defined
and won’t be changed in the future.

A

closed

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

● 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.
● This means that the subclass should remain compatible with the
behavior of the superclass.

A

Liskov Substitution Principle

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

Liskov
Substitution Principle is named by ___ , who defined it in 1987 in
her work Data abstraction and hierarchy

A

Barbara Liskov

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

The substitution principle has a set of formal
requirements for subclasses , and specifically for
their methods, which are as follows:

A
  1. Parameter types in a method of a
    subclass should match or be more abstract
    than parameter types in the method of the
    superclass.
  2. 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.
  3. A method in a subclass
    shouldn’t throw types of
    exceptions which the base method isn’t expected to
    throw.
  4. A subclass shouldn’t strengthen pre
    conditions.
  5. A subclass shouldn’t weaken post
    conditions.
  6. Invariants of a superclass must be preserved.
  7. 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
10
Q

● Clients shouldn’t be forced to depend on
methods they do not use.
● Try to make your interfaces narrow enough
that client classes don’t have to implement
behaviors they don’t need.
● Clients should implement only those methods
that they really need. Otherwise, a change to
a “fat” interface would break even clients
that don’t use the changed methods.

A

Interface Segregation Principle

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


High level classes shouldn’t depend on low level classes. Both
should depend on abstractions.

Abstractions shouldn’t depend on details. Details should
depend on abstractions.

A

Dependency Inversion Principle

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

Usually when designing software, you can make a distinction
between two levels of classes.

A

Low level classes
High level classes

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

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

A

Low level classes

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

contain complex business logic
that directs low level classes to do something.

A

High level classes

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

The dependency inversion principle suggests changing the direction of this
dependency by:

A

■ Describe interfaces for low level operations that high level classes rely on,
preferably in business terms.
■ Make high level classes dependent on those interfaces, instead of on
concrete low level classes.
■ Once low level classes implement these interfaces, they become
dependent on the business logic level

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