5.13. Objects-oriented programming II (Mandatory)

5.13. Objects-oriented programming II (Mandatory)

Figure 5.13: Connection Map. CS113 Objects-oriented programming II

5.13.1. Justification ↑ Back to top

This is the third course in the sequence of introductory courses in computer science. This course explores advanced C++17/C++20 features focusing on high-performance systems development. Key topics include template metaprogramming, move semantics, perfect forwarding, RAII optimization, multiple/virtual inheritance patterns, concurrency with std::thread and async/await, lock-free programming, modern C++ paradigms such as CRTP and expression templates, and interfacing C++ with other languages. The course prepares students for game engines, high-performance computing, and embedded development where C++ dominates.

5.13.2. Generales Goals ↑ Back to top

  1. Master advanced C++17/C++20 features including templates and metaprogramming
  2. Develop skills in concurrent and systems programming
  3. Understand performance optimization techniques
  4. Prepare for high-performance computing applications
  5. Master template metaprogramming and compile-time computation

5.13.3. Contribution to Outcomes ↑ Back to top

AG-C09) Design and Development of Solutions: Designs, implements, and evaluates solutions for complex computing problems. (Usage)
AG-C12) Applies computer science theory and software development fundamentals to produce computer-based solutions. (Assessment)

5.13.4. Content ↑ Back to top

5.13.4.1. Object-Oriented Programming: Encapsulation, Subtyping, and Reflection (8 hours) [Skills AG-C09,AG-C12] ↑ Back to top

Bibliography: (Stroustrup, 2013; Josuttis, 2019; Vandevoorde et al., 2017a)

Topics

  1. Collection classes, iterators, and other common library components.
  2. Associative containers (std::set, std::map, unordered variants)
  3. Container adapters (stack, queue, priority_queue)
  4. Advanced STL algorithms
  5. Functors and predicates
  6. Iterator categories and traits

Learning Outcomes

  1. Use collection classes and iterators effectively to solve a problem [Usage]
  2. Define and use iterators and other operations on aggregates, including operations that take functions as arguments, in multiple programming languages, selecting the most natural idioms for each language [Assessment]
  3. Compare and contrast the benefits and costs/impact of using inheritance (subclasses) and composition (specifically, how to base composition on higher order functions) [Usage]
  4. Implement custom allocators for STL containers [Usage].
5.13.4.2. Type Systems: Polymorphism and Complementary Typing (12 hours) [Skills AG-C09,AG-C12] ↑ Back to top

Bibliography: (Stroustrup, 2013; Vandevoorde et al., 2017a; Stroustrup, 2022)

Topics

  1. Generic types (parametric polymorphism):
    1. Definition and advantages of polymorphism: parametric, subtyping, overloading, and coercion
    2. Comparison of monomorphic and polymorphic types
    3. Comparison with ad-hoc polymorphism (overloading) and subtype polymorphism
    4. Generic parameters and typing
    5. Use of generic libraries such as collections
    6. Comparison with ad hoc polymorphism (overloading) and subtype polymorphism
    7. Prescriptive vs descriptive polymorphism
    8. Implementation models of polymorphic types
    9. Subtyping enumerate
    10. SFINAE (Substitution Failure Is Not An Error): historical foundation of constrained generic programming in C++, the basis of pre-C++20 libraries.
    11. Concepts (C++20): declarative syntax to constrain template parameters, the modern successor to SFINAE with better error diagnostics.
    12. if constexpr (C++17): compile-time branching, replacing much of the tag dispatch previously handled with SFINAE.
    13. Perfect forwarding and universal references
    14. Variadic templates
    15. Compile-time computation with constexpr and consteval

    Learning Outcomes

    1. Define and use program pieces (such as functions, classes, methods) that use generic types, including for collections [Assessment]
    2. Discuss the differences among generics, subtyping, and overloading [Assessment]
    3. Apply Concepts to constrain template parameters and improve error diagnostics [Usage].
    4. Distinguish when to use Concepts, if constexpr, or legacy SFINAE when maintaining existing C++ code [Assessment].
    5. Implement perfect forwarding for efficient argument passing [Usage].
    5.13.4.3. Memory Management (8 hours) [Skills AG-C09,AG-C12] ↑ Back to top

    Bibliography: (Meyers, 2014; Stroustrup, 2013)

    Topics

    1. Low level allocation and accessing of high-level data structures such as basic data types, n-dimensional array, vector, record, and objects
    2. Return from procedure as automatic deallocation mechanism for local data elements in the stack
    3. Manual memory management: allocating, de-allocating, and reusing heap memory
    4. Automated memory management: garbage collection as an automated technique using the notion of reachability
    5. Lvalues and rvalues in C++11/14/17/20
    6. Move constructors and move assignment operators
    7. Rvalue references and reference collapsing
    8. Resource Acquisition Is Initialization (RAII) pattern
    9. Smart pointer customization
    10. Memory leak detection and prevention

    Learning Outcomes

    1. Explain why memory leaks and dangling pointer problems occur, and what can be done by a programmer to avoid/fix them [Usage]
    2. Explain how programming language implementations typically organize memory into global data, text, heap, and stack sections and how features such as recursion and memory management map to this memory model [Assessment]
    3. Explain how a core language construct, such as data abstractions and control abstractions, is executed [Assessment]
    4. Implement move semantics for resource optimization [Usage].
    5. Design RAII classes for exception-safe resource management [Usage].
    5.13.4.4. Parallel and Distributed Computing (12 hours) [Skills AG-C09,AG-C12] ↑ Back to top

    Bibliography: (Williams, 2019; Stroustrup, 2013)

    Topics

    1. Safety and liveness:
      1. Race conditions
      2. Dependencies/preconditions
      3. Fault models
      4. Termination enumerate
      5. Programming models:
        1. Actor models
        2. Procedural and reactive models
        3. Synchronous/asynchronous programming models
        4. Data parallelism enumerate
        5. Communication and coordination:
          1. Mutexes
          2. Message-passing
          3. Shared memory
          4. Cobegin-coend
          5. Monitors
          6. Channels
          7. Threads
          8. Guards enumerate
          9. std::thread and thread management
          10. std::jthread (C++20): automatic joining (RAII) and cooperative cancellation via stop_token
          11. Mutexes, locks, and condition variables
          12. C++20 synchronization primitives: std::latch, std::barrier, std::counting_semaphore
          13. Atomic operations and lock-free programming
          14. std::async and futures
          15. std::execution and the senders-receivers model (C++26, experimental): a preview of where standard C++ concurrency is heading, presented at a conceptual level only, not evaluated in lab given its limited availability (partial in GCC)
          16. Thread-safe design patterns
          17. Data races and deadlock prevention

          Learning Outcomes

          1. Implement correct concurrent programs using multiple programming models, such as shared memory, actors, futures, synchronization constructs, and data-parallelism primitives [Usage]
          2. Use synchronization constructions such as monitor/synchronized methods in a simple program [Usage]
          3. Use a message-passing model to analyze a communication protocol [Assessment]
          4. Implement lock-free data structures using atomics [Usage].
          5. Differentiate std::thread from std::jthread and justify when to use each [Usage].
          6. Analyze thread-safety of concurrent algorithms [Assessment].
          5.13.4.5. Advanced Programming Constructs (8 hours) [Skills AG-C09,AG-C12] ↑ Back to top

          Bibliography: (Stroustrup, 2013; Vandevoorde et al., 2017b)

          Topics

          1. Object-oriented abstractions: multiple inheritance, mixins, traits, multimethods
          2. Metaprogramming: macros, generative programming, model-based development
          3. Multiple inheritance and virtual inheritance
          4. CRTP (Curiously Recurring Template Pattern)
          5. deducing this (C++23): simplifies CRTP by removing the need for static_cast<Derived&>(*this) for static polymorphism
          6. Expression templates
          7. Type traits and compile-time introspection
          8. Policy-based design
          9. Interface design for libraries

          Learning Outcomes

          1. Use various advanced programming constructs and idioms correctly [Usage]
          2. Discuss how various advanced programming constructs aim to improve program structure, software quality, and programmer productivity [Assessment]
          3. Discuss how various advanced programming constructs interact with the definition and implementation of other language features [Assessment]
          4. Implement CRTP for static polymorphism [Usage].
          5. Design extensible library interfaces using policy-based design [Usage].
          5.13.4.6. Systems Execution and Memory Model (8 hours) [Skills AG-C09,AG-C12] ↑ Back to top

          Bibliography: (Stroustrup, 2013; Williams, 2019)

          Topics

          1. Run-time representation of data abstractions such as variables, arrays, vectors, records, pointer-based data elements such as linked-lists and trees, and objects
          2. Data structures for translation, execution, translation, and code mobility such as stack, heap, aliasing (sharing using pointers), indexed sequence and string
          3. Implementation of the dynamic dispatch introduced in OOP I: virtual function table (vtable), vtable pointer (vptr), and its memory/performance cost versus static dispatch
          4. Interfacing C++ with other languages (FFI)
          5. System calls and OS interaction
          6. Memory-mapped I/O
          7. Performance profiling and benchmarking
          8. Optimization techniques for HPC

          Learning Outcomes

          1. Explain how a core language construct, such as data abstractions and control abstractions, is executed [Usage]
          2. Explain how programming language implementations typically organize memory into global data, text, heap, and stack sections and how features such as recursion and memory management map to this memory model [Assessment]
          3. Explain why memory leaks and dangling pointer problems occur, and what can be done by a programmer to avoid/fix them [Usage]
          4. Profile and optimize C++ programs for performance [Usage].
          5. Explain how the compiler implements runtime polymorphism via vtables [Assessment].
          6. Interface C++ code with C libraries [Usage].
          5.13.4.7. Advanced Programming Constructs (6 hours) [Skills AG-C09,AG-C12] ↑ Back to top

          Bibliography: (Gamma et al., 1994a; Stroustrup, 2013)

          Topics

          1. Object-oriented abstractions: multiple inheritance, mixins, traits, multimethods
          2. Creational, structural, and behavioral patterns
          3. Thread-safe singleton patterns
          4. Modern C++ design idioms
          5. Dependency injection and inversion of control

          Learning Outcomes

          1. Use various advanced programming constructs and idioms correctly [Usage]
          2. Discuss how various advanced programming constructs aim to improve program structure, software quality, and programmer productivity [Assessment]
          3. Discuss how various advanced programming constructs interact with the definition and implementation of other language features [Familiarity]
          4. Implement thread-safe design patterns [Usage].
          5. Evaluate architectural trade-offs in C++ systems [Assessment].
          5.13.4.8. Advanced Programming Constructs (6 hours) [Skills AG-C09,AG-C12] ↑ Back to top

          Bibliography: (Meyers, 2014; Stroustrup, 2013)

          Topics

          1. Control abstractions: exception handling, continuations, monads.
          2. Compiler optimizations and flags
          3. Benchmarking methodologies
          4. Cache-friendly data structures
          5. Branch prediction and alignment
          6. Reducing compilation time
          7. Continuous integration for performance testing

          Learning Outcomes

          1. Use various advanced programming constructs and idioms correctly [Usage]
          2. Discuss how various advanced programming constructs aim to improve program structure, software quality, and programmer productivity [Assessment]
          3. Discuss how various advanced programming constructs interact with the definition and implementation of other language features [Familiarity]
          4. Apply optimization techniques to improve program performance [Usage].
          5. Interpret benchmark results to guide optimization decisions [Usage].
          5.13.4.9. Version Control and CI/CD (4 hours) [Skills AG-C09,AG-C12] ↑ Back to top

          Bibliography: (Stroustrup, 2013; Stroustrup, 2022)

          Topics

          1. Software process automation:
            1. Build systems - the value of fast, hermetic, reproducible builds, compare/contrast approaches to building a project.
            2. Continuous Integration (CI) - the use of automation and automated tests to do preliminary validation that the current head/trunk revision builds and passes (basic) tests.
            3. Continuous Deployment (CD) - the use of automation to automatically release every change that passes the automated tests to the production environment, ensuring frequent and reliable deliveries.
            4. Dependency management - updating external/upstream dependencies, package management, SemVer. enumerate
            5. Build systems for C++: CMake, the de facto industry standard
            6. Modern alternatives: xmake, Meson, and Bazel – comparing declarative approaches versus Lua/Python-based ones
            7. Organizing multi-file projects: translation units, headers, static and dynamic libraries
            8. Dependency management in C++ (vcpkg, Conan)

            Learning Outcomes

            1. Understand the use of CI/CD systems as a ground-truth for the state of the team's shared code (build and test success) [Familiarity]
            2. Configure a multi-file C++ project using a declarative build system [Usage].
            3. Compare CMake with at least one modern alternative (xmake, Meson, or Bazel) in terms of build speed and reproducibility [Assessment].

            5.13.5. Bibliography ↑ Back to top

            Stroustrup, B. (2013). The C++ Programming Language. Addison-Wesley Professional, Upper Saddle River, NJ, 4th edition.

            Josuttis, N. M. (2019). C++17: The Complete Guide. Pearson Education, Indianapolis, IN, 1st edition.

            Vandevoorde, D., Josuttis, N. M., and Gregor, D. (2017a). C++ Templates: The Complete Guide. Addison-Wesley Professional, Upper Saddle River, NJ, 2nd edition.

            Stroustrup, B. (2022). A Tour of C++. Addison-Wesley Professional, Boston, MA, 3rd edition.

            Meyers, S. (2014). Effective Modern C++: 42 Specific Ways to Improve Your Use of C++11 and C++14. O'Reilly Media, Sebastopol, CA, 1st edition.

            Williams, A. (2019). C++ Concurrency in Action. Manning Publications, Shelter Island, NY, 2nd edition.

            Vandevoorde, D., Josuttis, N. M., and Gregor, D. (2017b). C++ Templates: The Complete Guide. Addison-Wesley Professional, Upper Saddle River, NJ, 2nd edition.

            Gamma, E., Helm, R., Johnson, R., and Vlissides, J. (1994a). Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley Professional, Reading, MA, 1st edition.

            Spotted a typo, an outdated course, a broken link, or have a suggestion? Let us know.

            Scan to open on your phone