OO Design Principles (PPT 15) Flashcards

1
Q

What are the three design principles to be aware of?

A
  • Open-closed principle
  • Dependency-Inversion principle
  • Liskov-substitution principle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Open-Closed principle?

A

Classes should be open for extension but closed to modification. Meaning you should be able to extend the behaviour of a class without modifying the already working code

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

How do you implement the open closed principle?

A

Implement Inheritance

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

What is the Dependency-Inversion Principle?

A

High level modules should not depend on low level modules, both should depend on an abstraction.

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

How to you solve the Dependency-Inversion Principle?

A

You define an abstraction of the behaviour. Each device must derive itself from this behaviour

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

What is the Liskov Substitution Principle?

A

Child classes should be substitutable for their parents

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

How do we prevent the Liskov Substitution Principle?

A
  • Design by contract (define pre and post conditions on operations)
  • Post conditions should be at least as strong as the parent class
  • Also use pre conditions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly