Hoofdstuk 6 - Design By Contract Flashcards

1
Q

What is the distinction between Testing and Design by Contract? Why are they complementary techniques?

A

◦ Testing tries to diagnose defects while Design by Contract tries to prevent defects
◦ They are complementary as you can’t prevent all defects and you can’t diagnose all defects

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

What is the weakest possible condition in logic terms? And the strongest?

A

◦ Weakest: true
◦ Strongest: false

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

If you have to implement an operation on a class, would you prefer weak or strong pre- and postconditions? And what about the class invariant?

A

A lazy developer wants a strong precondition, a weak postconditions and the invariant doesn’t matter

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

If a subclass overrides an operation, what is it allowed to do with the pre- and postcondition? And what about the class invariant?

A

◦ Postcondition: stronger or equal
◦ Precondition: weaker or equal
◦ Invariant: equal

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

Compare Testing and Design by contract using the criteria “Correctness” and “Traceability”.

A

◦ Both support traceability if you do it right
◦ Both do not guarantee correctness but sum is more than it’s parts

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

What is the Liskov substitution principle? Why is it important in OO development?

A

◦ You may substitute an instance of a subclass for any of its superclasses
◦ It tells us what a subclass may do with pre- and post-conditions and invariants.

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

What is behavioral subtyping?

A

It is the principle that subclasses should satisfy the expectations of clients accessing subclass objects through references of superclass type, not just as regards syntactic safety but also as regards behavioral correctness.

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

When is a pre-condition reasonable?

A

◦ It must be possible to justify the need for the precondition in terms of the requirements specification only
◦ Clients should be able to satisfy and check it.

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