Spawning Game Objects with the Factory Pattern
In this chapter, we will explore the Factory pattern, a creational design pattern that allows us to establish a default interface in a superclass, which will allow it to create new objects. Subclasses can then change the type or the way these objects are created, allowing us to use a common interface to create a range of different objects.
By using the Factory pattern, we can decouple an object’s creational responsibility and delegate it to the factory object, which will take care of all the procedures necessary to create this object in the application. Generally speaking, the Factory pattern can create any type of object. Keep in mind our definition of an object: the concrete instance of a class. This means that it does not necessarily create game objects, in other words, objects that are part of the game world. In this chapter, we will create a specialization of the Factory pattern known as Spawner, which is specifically designed...