Exam 3 Flashcards
encapsulation
group data and operations in one place
hide irrelevant deails (using visibility modifiers)
Subtyping
define functions for that type
static dispatch
dispatch to the parent class
easier to implement and more efficient
compiler can always tell which implementation at compile time
dynamic dispatch
dispatch to the implementation based on the actual object
less efficient but provides better extensibility
virtual table
shared table containing method binaries,
one per class
Upcasting is always safe
Down casting not safe
Operation classifications
creators, producers, mutators, observers
Contract
precondition - assumptions on inputs
side effects - changes to the value
post condition - functionality of the operation
invariants - a property that is always true throughout the operation
Why contract
separation of concerns:
preconditions/input values - user’s responsibility
side effects - users should be awawar of
postconditions/output values - ADT’s responsibility
Loop invariant
Initially true: P-> Inv true after each iter: Inv ^E -> wp (s, Iv) termination of loop -> post cond Inv ^notE ->Q