A component-based system can be implemented in many ways. So, before we write any code, let's look at some possibilities. The goal is to break reusable behavior into succinct components and be able to add and remove them from the existing objects with ease. All objects share a common base class named object so we'll add the facility to add components to and remove them from this class. We can then ensure that it will be propagated to all the subsequent classes in the project.
There are a number of ways to implement a component-based approach, and there is no single right answer. For example, we could create a function to add or remove each component individually. Here's an example:
bool AttachSpriteComponent(SpriteComponent spriteCompontent); bool AttachInputComponent(InputComponent inputComponent);
While this will make things straightforward, we will have a lot of duplicate code in the class. Also, every time we add a component, we will have to create two matching...