Design Principles Flashcards

1
Q

Princple of Least Knowledge (Law of Demeter)

A

A method M in an object O can call on:

  • methods in O
  • methods of parameters to M
  • method of object instantiated
  • method of object that is part of O
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Liskov Substitution Principle

A

Subtypes should be substitutable for their base types

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

Encapsulate what varies

A
  • separate varying aspects of code so changing doesn’t affect rest of code
  • encapsulate behaviour
  • encapsulate object creation
  • encapsulate method invocation (command)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Favour composition over inheritance

A
  • enables to change behaviour at run time

- delegate the implementation of a behaviour to composed class

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

loosely-coupled design

A
  • loosely coupled designs minimise interdependency between objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Hoolywood principle: don’t call us, we’ll call you

A
  • enable low-level components to hook themselves into a system, but the high-level components decide “when and how” they are needed
  • i.e. template method pattern
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

OCP

A
  • new changes must be implemented by new code not altering existing
  • i.e. strategy, state, decorator and template
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

SRP

A

classes should only have one reason to change = high cohesion

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

Program to an interface (super-type) and not to an implementation

A
  • the declared type of the variable should be a super-type (abstract class or interface)
  • helps use polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Depend upon abstractions. Do not depend on create classes

A
  • A high level module should not depend on “low-level” modules, but both should depend on abstractions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly