- ES Español

- EN English

5.13. Objects-oriented programming II (Mandatory)
- Semester: 3rd Sem. Credits: 4
- Hour of this course: Theory: 2 hours; Practice: 2 hours; Laboratory: 2 hours;
- Syllabus:
- htmlonly

Español

English - Prerrequisites:
- CS112 Objects-oriented programming I (2nd Sem) itemize
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
- Master advanced C++17/C++20 features including templates and metaprogramming
- Develop skills in concurrent and systems programming
- Understand performance optimization techniques
- Prepare for high-performance computing applications
- 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
- Collection classes, iterators, and other common library components.
- Associative containers (std::set, std::map, unordered variants)
- Container adapters (stack, queue, priority_queue)
- Advanced STL algorithms
- Functors and predicates
- Iterator categories and traits
Learning Outcomes
- Use collection classes and iterators effectively to solve a problem [Usage]
- 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]
- Compare and contrast the benefits and costs/impact of using inheritance (subclasses) and composition (specifically, how to base composition on higher order functions) [Usage]
- 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
- Generic types (parametric polymorphism):
- Definition and advantages of polymorphism: parametric, subtyping, overloading, and coercion
- Comparison of monomorphic and polymorphic types
- Comparison with ad-hoc polymorphism (overloading) and subtype polymorphism
- Generic parameters and typing
- Use of generic libraries such as collections
- Comparison with ad hoc polymorphism (overloading) and subtype polymorphism
- Prescriptive vs descriptive polymorphism
- Implementation models of polymorphic types
- Subtyping enumerate
- SFINAE (Substitution Failure Is Not An Error): historical foundation of constrained generic programming in C++, the basis of pre-C++20 libraries.
- Concepts (C++20): declarative syntax to constrain template parameters, the modern successor to SFINAE with better error diagnostics.
- if constexpr (C++17): compile-time branching, replacing much of the tag dispatch previously handled with SFINAE.
- Perfect forwarding and universal references
- Variadic templates
- Compile-time computation with constexpr and consteval
Learning Outcomes
- Define and use program pieces (such as functions, classes, methods) that use generic types, including for collections [Assessment]
- Discuss the differences among generics, subtyping, and overloading [Assessment]
- Apply Concepts to constrain template parameters and improve error diagnostics [Usage].
- Distinguish when to use Concepts, if constexpr, or legacy SFINAE when maintaining existing C++ code [Assessment].
- 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
- Low level allocation and accessing of high-level data structures such as basic data types, n-dimensional array, vector, record, and objects
- Return from procedure as automatic deallocation mechanism for local data elements in the stack
- Manual memory management: allocating, de-allocating, and reusing heap memory
- Automated memory management: garbage collection as an automated technique using the notion of reachability
- Lvalues and rvalues in C++11/14/17/20
- Move constructors and move assignment operators
- Rvalue references and reference collapsing
- Resource Acquisition Is Initialization (RAII) pattern
- Smart pointer customization
- Memory leak detection and prevention
Learning Outcomes
- Explain why memory leaks and dangling pointer problems occur, and what can be done by a programmer to avoid/fix them [Usage]
- 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]
- Explain how a core language construct, such as data abstractions and control abstractions, is executed [Assessment]
- Implement move semantics for resource optimization [Usage].
- 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
- Safety and liveness:
- Race conditions
- Dependencies/preconditions
- Fault models
- Termination enumerate
- Programming models:
- Actor models
- Procedural and reactive models
- Synchronous/asynchronous programming models
- Data parallelism enumerate
- Communication and coordination:
- Mutexes
- Message-passing
- Shared memory
- Cobegin-coend
- Monitors
- Channels
- Threads
- Guards enumerate
- std::thread and thread management
- std::jthread (C++20): automatic joining (RAII) and cooperative cancellation via stop_token
- Mutexes, locks, and condition variables
- C++20 synchronization primitives: std::latch, std::barrier, std::counting_semaphore
- Atomic operations and lock-free programming
- std::async and futures
- 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)
- Thread-safe design patterns
- Data races and deadlock prevention
Learning Outcomes
- Implement correct concurrent programs using multiple programming models, such as shared memory, actors, futures, synchronization constructs, and data-parallelism primitives [Usage]
- Use synchronization constructions such as monitor/synchronized methods in a simple program [Usage]
- Use a message-passing model to analyze a communication protocol [Assessment]
- Implement lock-free data structures using atomics [Usage].
- Differentiate std::thread from std::jthread and justify when to use each [Usage].
- 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
- Object-oriented abstractions: multiple inheritance, mixins, traits, multimethods
- Metaprogramming: macros, generative programming, model-based development
- Multiple inheritance and virtual inheritance
- CRTP (Curiously Recurring Template Pattern)
- deducing this (C++23): simplifies CRTP by removing the need for static_cast<Derived&>(*this) for static polymorphism
- Expression templates
- Type traits and compile-time introspection
- Policy-based design
- Interface design for libraries
Learning Outcomes
- Use various advanced programming constructs and idioms correctly [Usage]
- Discuss how various advanced programming constructs aim to improve program structure, software quality, and programmer productivity [Assessment]
- Discuss how various advanced programming constructs interact with the definition and implementation of other language features [Assessment]
- Implement CRTP for static polymorphism [Usage].
- 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
- Run-time representation of data abstractions such as variables, arrays, vectors, records, pointer-based data elements such as linked-lists and trees, and objects
- Data structures for translation, execution, translation, and code mobility such as stack, heap, aliasing (sharing using pointers), indexed sequence and string
- Implementation of the dynamic dispatch introduced in OOP I: virtual function table (vtable), vtable pointer (vptr), and its memory/performance cost versus static dispatch
- Interfacing C++ with other languages (FFI)
- System calls and OS interaction
- Memory-mapped I/O
- Performance profiling and benchmarking
- Optimization techniques for HPC
Learning Outcomes
- Explain how a core language construct, such as data abstractions and control abstractions, is executed [Usage]
- 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]
- Explain why memory leaks and dangling pointer problems occur, and what can be done by a programmer to avoid/fix them [Usage]
- Profile and optimize C++ programs for performance [Usage].
- Explain how the compiler implements runtime polymorphism via vtables [Assessment].
- 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
- Object-oriented abstractions: multiple inheritance, mixins, traits, multimethods
- Creational, structural, and behavioral patterns
- Thread-safe singleton patterns
- Modern C++ design idioms
- Dependency injection and inversion of control
Learning Outcomes
- Use various advanced programming constructs and idioms correctly [Usage]
- Discuss how various advanced programming constructs aim to improve program structure, software quality, and programmer productivity [Assessment]
- Discuss how various advanced programming constructs interact with the definition and implementation of other language features [Familiarity]
- Implement thread-safe design patterns [Usage].
- 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
- Control abstractions: exception handling, continuations, monads.
- Compiler optimizations and flags
- Benchmarking methodologies
- Cache-friendly data structures
- Branch prediction and alignment
- Reducing compilation time
- Continuous integration for performance testing
Learning Outcomes
- Use various advanced programming constructs and idioms correctly [Usage]
- Discuss how various advanced programming constructs aim to improve program structure, software quality, and programmer productivity [Assessment]
- Discuss how various advanced programming constructs interact with the definition and implementation of other language features [Familiarity]
- Apply optimization techniques to improve program performance [Usage].
- 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
- Software process automation:
- Build systems - the value of fast, hermetic, reproducible builds, compare/contrast approaches to building a project.
- 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.
- 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.
- Dependency management - updating external/upstream dependencies, package management, SemVer. enumerate
- Build systems for C++: CMake, the de facto industry standard
- Modern alternatives: xmake, Meson, and Bazel – comparing declarative approaches versus Lua/Python-based ones
- Organizing multi-file projects: translation units, headers, static and dynamic libraries
- Dependency management in C++ (vcpkg, Conan)
Learning Outcomes
- 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]
- Configure a multi-file C++ project using a declarative build system [Usage].
- 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.