C C T B H P N

Lecture #11 - Open/Closed Principle

Prefer wrap and derive over change

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 presents the Open/Closed Principle, an ideal model for software development. We discuss how the C++ language can be used to build software following the 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. Readings for this Lecture:

    Class Text, CPPP:
    • review Chapter 15 - Object Oriented Programming, Chapter 16 - Templates
  3. 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 put an updated version of the Parser in the Project2HelpS2019 folder. It fixes a bug I spotted in the AST display. I've wanted to update the tokenizer to a State-Based model, like we used in CSE681 - Software Modeling and Analysis, Fall 2018. That turned out to be a bit more work than I expected, but the results seem solid, and I recommend its use for Project #2. You will find the Parser Blog helpful for Project #2. Dll Loader with hosted resource
    Shows how a library can use resources provided by its host.
    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.
  4. Class Layout demo
    Shows that each object of a polymorphic class (one with virtual functions) contains a pointer to the class VfPtrTable. Also shows that composed objects are contained by the composer, and base objects are contained by the derived class.
  5. new style casts demo, const pointers demo
  6. Callable Objects:

    Simple Demo of Callable Objects, Callable Objects Examples
    Illustrates use of functions, function pointers, std::function<R(A...)>, lambdas, and lamda closures.
  7. Applications of Inheritance

    The Command Pattern is an interesting application of inheritance:
  8. Open/Closed Principle

    Open/Closed Principle, pptx
    Another fundamental OOD principle that argues for using inheritance "hooks" and template-based classes. Extensible Parsing, used in XmlDocument, Blog on Parser
    This demonstrates the Open/Closed Principle by binding rules and actions to interfaces, used by the parser. The Adapter Pattern, pptx
    This pattern, one of about 30 we discuss in CSE776 - Design Patterns, illustrates one way to adhere to the Open/Closed Principle. Heterogeneous List Structure
    Unusual use of Liskov Substitution Satisfying the Open/Closed Principle, pptx
    Protocols, Hooks, Policies, Inheriting Concrete Classes.
  9. Parser - a design example

    Parser Package diagram, Parsing Blog
    Illustrates segregation into application specific and reusable parts. Also illustrates isolation of code from its clients by using an interface and an object factory. Tokenizer class diagram
    Shows how a complex design can be decomposed into smaller managable parts. This design has some circular dependencies - required by the need to communicate state information between parts. The details of the Toker implementation show how to manage those. Parser code folder
    This code is the same as Project2Starter in the Project2HelpS19 folder.
  10. Run-Time Type Indentification Presentation
    RTTI is, perhaps, the antithesis of the Open/Closed Principle. Paradoxically, I used it building the trace class.
  11. Exceptions, pptx
  12. Exception demo
  13. Enforcements
  14. Software Design Blog Entries:
  15. 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
  16. These are the most important items from today's lecture:

    Callable Objects
    Illustrates use of functions, function pointers, std::function<R(A...)>, lambdas, and lamda closures.

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

    Extensible Parsing, Blog on Parser
    This demonstrates the Open/Closed Principle by binding rules and actions to interfaces, used by the parser.

CST strip