C C T B H P N

Lecture #12 - Dependency Inversion Principle

Interfaces and Object Factories

Web Resources:

CppCon - 2014, Going Native 2013
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
Excellent C++ Q&A, Excellent reference - CppReference.com, CPlusPlus.com, C++ TechLinks

Content:

This lecture covers Interfaces, Object Factories, and the Dependency Inversion Principle.
  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. Projects:

    Resources for Project #2: - Source code publisher for projects
    Project #2 statement, Project2HelpS2019
    OODProject2Helper adds show/hide capability to the demo output. I've posted Ammar Salman's solution for Project #1, and an updated version of the Parser with an Executive, in the Project2HelpS19 folder. I recommend its use for Project #2. You will also find the Parser Blog helpful for Project #2. C++ Survival Guide, doc
    Visual Studio help notes, Code Analyzer
    Project Submissions

    Current Versions of Code:

    If you go to other folders in the college server you are very likely to download out-of-date code, usually correct, but won't compile with demonstration code that uses newer features.
    Policy for due date extensions - only for certified illness and work or interview trips out of town:
    one week extension, with proof. Only one extension per project.
  3. Principles

    Liskov Substitution Principle, pptx
    This is a fundamental OOD principle, with some surprising subtleties when using C++. Open/Closed Principle, pptx
    Another fundamental OOD principle that argues for using inheritance "hooks" and template-based classes. The Dependency Inversion Principle, pptx
    Components should depend on abstractions, not other components.
    Classic Factory structure, Classic Factory creating polymorphic objects
    Illustrates how to create instances of a polymorphic type with clients knowing only the base class and factory interfaces. Object Factory Structure, Object Factory Project
    This project implements a factory that allows clients to use derived classes but only bind to their abstractions. It also demonstrates the use of products with multiple interfaces. Extensible Object Factory Structure, Programming to Interface Project
    This project implements a template-based "pluggable object factory" and shows how to access members of a hierarchy through an interface. Code Parser
    Illustrates very extensible design using interfaces and object factory. Programming to Interfaces Presentation, pptx
    Discusses interfaces, layers, factories, and breaking design, compile, and static link dependencies. MakeDLL Structure, MakeDLL: Dynamic Link Library Project
    This project demonstrates that compile and static link dependencies can be broken by programming to interfaces and using object factories. DLLDemo-Protocol Project
    Demonstrates how Dynamic Link Libraries are loaded implicitly and explicitly.
    To build successfully you need to build the libraries first, then the clients. Dll Loader with hosted resource
    Shows how a library can use resources provided by its host.
    Interface Segregation Principle, pptx
    Another fundamental OOD principle that argues for partitioning interfaces.
  4. Reuse and the Product Model

  5. Run-Time Type Indentification Presentation
    RTTI is, perhaps, the antithesis of the Open/Closed Principle. Paradoxically, I used it building the trace class.
  6. Exceptions
  7. Exception demo
  8. Enforcements
  9. Software Design Blog Entries:
  10. Software design presentations: There is no receipe for good design - it's a creative process that usually strives to balance a number of competing factors. Our goals are to build programs and software systems that are elegant and simple, make their intents clear, and make them fast and reliable. The presentations below provide guidance to help move us toward those goals.
    Software Design Goals, ppt
    Design Goals and Attributes - used to measure designs. Design Strategies, pptx
    Discusses styles of design and binding. Design Guidelines, pptx
    Small principles and useful techniques Design Issues, pptx
    Practical issues and problems of design and implementation
  11. These are the most important items from today's lecture:

    Liskov Substitution Principle
    This is a fundamental OOD principle, with some surprising subtleties when using C++.

    Open/Closed Principle
    Another fundamental OOD principle that argues for using inheritance "hooks" and template-based classes.

    The Dependency Inversion Principle
    Components should depend on abstractions, not other components.

    Interface Segregation Principle
    Another fundamental OOD principle that argues for partitioning interfaces.

    Classic Factory structure, Classic Factory creating polymorphic objects
    Illustrates how to create instances of a polymorphic type with clients knowing only the base class and factory interfaces.

    Object Factory Structure, Object Factory Project
    This project implements a factory that allows clients to use derived classes but only bind to their abstractions. It also demonstrates the use of products with multiple interfaces.

CST strip