CHAPTER 7Multiparadigm Design in C++

7.1 Introduction and Objectives

In this chapter we discuss the integration of modern features in C++ with object-oriented design techniques. The goal is to design robust and flexible classes in C++. We strive to design classes that have a single responsibility and that also have minimal coupling with other classes. In other words, a class should depend on a small set of classes to which it delegates. Furthermore, we discuss how to implement class hierarchies using subtype polymorphism, Curiously Recurring Template Pattern (CRTP), Strategy design pattern and by using a mix of object-oriented and functional programming styles. Instead of having to create class hierarchies with possibly many derived classes we can create a single class that is composed of one or more universal function wrappers (instances of std::function). These functions can be assigned to a range of target methods as described in Chapter 3. We have already seen an example in Chapter 6 (Section 6.8) when we discussed stochastic differential equations. In this sense we note that function wrappers are competitors to virtual functions.

We also give an overview of object-oriented software metrics that measure code quality by providing metrics for classes, their members as well as class hierarchies.

In general, we see objects and classes as important during the detailed design and implementation phases of software development. We do not use them as drivers to decompose a software ...

Get Financial Instrument Pricing Using C++, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.