Lecture Notes for Advanced Programming II

13 March 2001 - Virtual Classes


  1. to review

    1. classes without inheritance are great

    2. use inheritance to get polymorphism amoung classes

    3. virtual members give useful polymorphism - search from the bottom

  2. the virtual issues -

    1. what should be virtual

    2. destructors

    3. coupling

  3. what should be virtual

    1. make everything virtual - but that's expensive

    2. cost in time and space

  4. destructors

    1. what's the problem?

    2. non-virtual destructors in the parent class

    3. the child-class destructors can get skipped

    4. a puzzle

      1. class p {
          public:
           ~p() { cout << "delete a p.\n"; }
          };
        
        class c : public p {
          public:
            virtual ~c() { cout << "delete a c.\n"; }
          };
        
        void main(void) {
          p * pp = new c;
          delete pp;
          c * cp = new c;
          delete cp;
          }
        

      2. what's the output

  5. coupling

    1. coupling is a measure of independence among modules the more coupling between two modules, the less independent they are

    2. low coupling is important - easy to create, understand, modify

    3. coupling is hard to quantify

    4. value couples less strongly than behavior - behavior is function; value is data


This page last modified on 27 February 2001.