Concepts in Programming Flashcards

1
Q

Name the three key elements to Design by Contract?

A

1 Preconditions: What must be true in order for the routine to be called.

2 Postconditions: What the routine is guaranteed to do.

3 Class invariants: The conditions that that ensures the instances of a class stay invariant when applying the methods to them. A routine my break an invariant during the execution of the routine, but by the time the routine exits the invariant must be restored.

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

What are the first steps to take in implementing Design by Contract?

A

Enumerate:
1 The input domain range.
2 Boundary conditions.
3 What the routine promises to deliver (and what it doesn’t promises to deliver).

BEFORE writing any code!

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

Explain the crash early principle.

A

It is easier to identify the source of a problem if code crashes early.

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

Invariant (about an object)

A

When an object do not change when a given transformation is applied to it.

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