The alternative can be found by many names, though none are definitive yet. In this book, we will call it the Component Object Model, but others have called the Entity Component System or just Component System. No matter what you call it, the concept is surprisingly simple to learn and easy to implement.
The Component Object Model inverts the concept of the Decorator pattern, where each Decorator
added a new layer on top of the game object. Instead of layering our object
, which we have already seen problems with, we will put the decorations inside of it. Since we don't know how many we will need, our object
will hold a container of decorations, as opposed to a single pointer. In the simplest form, our object
is nothing more than a container for these components.
If you search for Component Object Model (or Component Based object Model) on the Internet, you will get results that are similar to what we saw in the Strategy pattern. The object contains hardcoded...