## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

, Design Patterns in Modern C++, https://doi.org/10.1007/978-1-4842-3603-1_3

# 3. Factories

(1)St. Petersburg, Russia

I had a problem and tried to use Java, now I have a ProblemFactory.

–Old Java joke.

This chapter covers two GoF patterns at the same time: Factory Method and Abstract Factory. These patterns are closely related, so we’ll discuss them together.

## Scenario

Let’s begin with a motivating example. Support you want to store information about a Point in Cartesian space. So you go ahead and implement something like this:

``1   struct Point``2   {``3     Point(const float x, const float y)``4       : x{x}, y{y} {}``5     float x, y; // strictly Cartesian``6   };``

So far, so good. But now, you also want to ...

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required