Lecture overview -- Keyboard shortcut: 'u'  Previous page: Inheritance and Contracts -- Keyboard shortcut: 'p'  Next page: Class invariants in the triangle class hierarchy -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 24 : 32
Object-oriented Programming in C#
Contracts and Assertions
Subcontracting

Due to polymorphism an instance of a subclass can act as stand in for an instance of the superclass

Consequently, the contracts of the subclass must comply with the contract of the superclass

The contract of a subclass must therefore be a subcontract of the superclass' contract

  • Assertions in a subclass

    • The precondition must not be stronger than the precondition in the superclass

    • The postcondition must not be weaker than the postcondition in the superclass

    • The class invariant must not be weaker than the invariant in the superclass

Operations in subclasses cannot arbitrarily redefine/override operations in superclasses