Lecture Notes for Advanced Programming II
18 January 2001 - Abstraction, Polymorphism, and Dynamic Binding
- abstraction - managing details
- a detail - any particular fact, claim, observation, ... about a thing
- why manage details - humans can't handle (remember, use) many details
at the same time; the 7 +/- 2 short-term memory problem
- humans ignore the myriad of details by ignoring them - focusing on the
wrong details, not focusing on the right ones
- abstraction is a technique for focusing on the right details
- selectively present important details by suppressing unimportant ones -
suppressing is not ignoring
- levels of details, layers of abstractions
- if detail a uses detail b, then a is at a higher level than b
- if the details in the abstraction layer a are at a higher level than
the details in abstraction layer b, then a is a higher level of
abstraction than b
- when is a level of detail appropriate for a layer of abstraction
- relevance - so what
- when a detail can vary widely and not change the abstraction, its
irrelevant and belongs at a lower level
- polymorphism - abstracting away types
- types may not be important at some level of detail - how many elements
in a list; a stack implementation
- polymorphism suppresses type details - polymorphic language features;
polymorphic data types, polymorphic functions, polymorphic variables
- polymorphism is valuable - abstraction and re-use
- strong typing is not polymorphic - type is always a detail; pascal
- dynamic typing can be polymorphic - java
- weak or broken typing can be polymorphic - c
- polymorphism occurs in many forms, but they all abstract types
- dynamic binding - making inheritance really polymorphic
- inheritance specifies a relation among classes - superclass-subclass,
parent-child
- many interpretations of the inheritance relation
- is-a relation - class s is-a class q
- class s is-a class f and class c is-a class f imply, at some level,
no difference between f and c - polymorphism
- member functions can break polymorphism
- parent classes can require child classes implement functions
- which function gets called - usually the wrong one; the topmost one
- virtual member functions repair polymorphism - call the bottom-most one
This page last modified on 18 January 2001.