I asked a question about implementing components here:
Am I on the right track with this component architecture?
But I had more questions I'd like to ask.
What's the best way to actually enforce the effects of components?
For instance, I have an item object, and an optional HealingComponent. The HealingComponent allows the item to be used as a HealingItem (for restoring HP/MP/etc.). I compose the HealingComponent from up to 3 StatAffectorComponents (one for HP, MP and SP). That Affector dictates the target stat, the target amount of change, and the type of change (%, absolute, etc.). All the basic components are being implemented in C++, but I intend to make the basic components extendtable from my scripts (python)
Now my question is, how do I actually enforce this?
I had three ideas about how to do it.
Allow the HealingComponent to contain a Use function that takes in the appropriate parameters and applies the StatAffector components against them. This has the advantage of making it much easier to override/customize the behaviour if I extend it with scripts, but I'm also tightly coupling the mechanics of usage with the item.
Allow the game mechanics to enforce the components. When the item is used as a Healing Item, the mechanics will extract the stat affectors and apply them against the appropriate targets its self. This has the advantage of seperating the item/component from it's usage, but at the same time, I'll have to change the mechanics anytime I decide to add expanded functionality/components to healing items. Healing items may not change their effects too often in development, but certain item classes might
Allow the item itself to define it's Use function and make it responsible for checking against it's components. This is further specializing Item away from a base entity, but has the advantage of being overridable with scripts to allow custom components
In general, what is the best way to do this?