---
title: "Comment by Paweł Kubik on \"Factory Design Pattern\" | Hashnode"
description: "The last point seems like a premature optimization. I doubt that dynamically-allocated std::map is any faster than whatever partially-compile-time mechanism is"
url: "https://hashnode.com/posts/factory-design-pattern/5ef9e6eca78de8267c2b26cb/comment/5f176ec54f0ccd6b8b03beb1"
---

[Discussion](https://hashnode.com/posts/factory-design-pattern/5ef9e6eca78de8267c2b26cb)

Comment [Factory Design Pattern](https://hashnode.com/posts/factory-design-pattern/5ef9e6eca78de8267c2b26cb)

[Paweł Kubik](https://hashnode.com/@pkubik)

[Jul 21, 2020](https://hashnode.com/posts/factory-design-pattern/5ef9e6eca78de8267c2b26cb/comment/5f176ec54f0ccd6b8b03beb1)

The last point seems like a premature optimization. I doubt that dynamically-allocated `std::map` is any faster than whatever partially-compile-time mechanism is being used by C++ compiler behind the scenes to handle virtual polymorphism.

Besides, I think you've missed an important point of a factory, which is to encode some object configuration within the factory class. You can have a bullet factory for a game, which is configured to create either red or grey bullets. Then you insert the red bullet factory to a `LaserGun` and the other one to a `BallisticGun`. You kind of did this with the `Point2D`/`Point3D` example but I don't think you've made it explicit enough.

Other than that, great introductory article. Keep going!
