Lecture #10 - Substitution Principle

Web Resources:

CppReference.com, CPlusPlus.com, C++ TechLinks
Going Native 2013 - many experts
Herb Sutter's Blog, Herb Sutter on C++11, Herb Sutter keynote - Going Native 2012
Scott Meyer's Blog, S.M. on thread suspension, S.M.: C++11 Sampler
Stroustrup's Home Page, Code Project, Boost Library

Content:

This lecture covers the Liskov Substitution Principle and its powerful applications in design. Polymorphism follows directly from Liskov Substitutability and helps us build loosely coupled systems.
  1. Syllabus
    Describes topics to be covered, reading material for you to digest before coming to class, and due dates for the assigned projects.
  2. Readings for this Lecture:

    Class Text, CPPP:
    • review Chapter 7 - Classes
    • read carefully Chapter 15 - Object Oriented Programming
  3. Projects:

    Project #1, Project1HelpS17
    NoSql Database

    Project #2, Project2HelpS17
    Parsing source code and building Dependency Relationships.

    Helper codes to look at:
    The Project2HelpS17 folder has a FileMgr Demo and a Tree Walk Demo both of which will be useful for Project #2.

    DemoCurrentDirectory
    Help with console processing that illustrates code language ideas and some C++11 constructs.

    Project #3
    Code Publisher

  4. Several aspects of Inheritance

    Using Inheritance, ppt
    Discusses several distinct design uses for inheritance.

    The Command Pattern is an interesting application of inheritance:

    Virtual Function Pointer Table structure
    Diagram shows how polymorphism works.

    Run-Time Type Information (RTTI), ppt

    Class Layout demo
    Shows that each object of a polymorphic class (one with virtual functions) contains a pointer to the class VfPtrTable.

  5. Errors using Polymorphism

    hiding
    Illustrates errors caused by inappropriate overloading and use of default parameters.

    importance of virtual destructors
    Demonstrates problems caused by omission of virtual destructors.

    Avoiding the Dark Corners

  6. Vectors of Polymorphic Objects - Example Project, Structure
    Shows how to use heterogeneous objects in an STL container.
  7. First Law of OOD

    Liskov Substitution Principle
    This is a fundamental OOD principle, with some surprising subtleties when using C++ (see example project below).

    Non-Virtual Interface Principle - a code example: see comments for explaination
    Liskov Substitutibility does not demand public virtual functions.

    Heterogeneous List - polymorphism without a common base class, Heterogeneous List Structure
    Unusual use of Liskov Substitution

  8. Functions, Function Objects, and Lambdas:

    Simple Demo of Callable Objects, More Examples of callable objects

    I've been asked about hash functions for the STL hashed containers. I found this good reference: STL Hash Functions

  9. Design Rules
    Design rules and idioms that transcend Object Oriented Design.
  10. These are the most important items from today's lecture:

    hiding
    Illustrates errors caused by inappropriate overloading and use of default parameters.

    importance of virtual destructors
    Demonstrates problems caused by omission of virtual destructors.

    Avoiding the Dark Corners

    Non-Virtual Interface Principle - a code example: see comments for explaination
    Liskov Substitutibility does not demand public virtual functions.

CST strip