Hoofdstuk 6 - Design By Contract Flashcards
What is the distinction between Testing and Design by Contract? Why are they complementary techniques?
◦ 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
What is the weakest possible condition in logic terms? And the strongest?
◦ Weakest: true
◦ Strongest: false
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 lazy developer wants a strong precondition, a weak postconditions and the invariant doesn’t matter
If a subclass overrides an operation, what is it allowed to do with the pre- and postcondition? And what about the class invariant?
◦ Postcondition: stronger or equal
◦ Precondition: weaker or equal
◦ Invariant: equal
Compare Testing and Design by contract using the criteria “Correctness” and “Traceability”.
◦ Both support traceability if you do it right
◦ Both do not guarantee correctness but sum is more than it’s parts
What is the Liskov substitution principle? Why is it important in OO development?
◦ 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.
What is behavioral subtyping?
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.
When is a pre-condition reasonable?
◦ 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.