I'm working on a few features for a strategy engine I'm making. I'm trying to figure out the best spots to separate the components, as either option will provide the same amount of coupling, with the same effectiveness.
For example, all players have a Damage component, a Player component, and a HealthBar component:
abstract class Damage
{
protected abstract void sendDamage(Player targetPlayer, int rawDamage);
public abstract int calculateRawDamage(Attack attackUsed);
public abstract void receiveDamage(int rawDamage);
}
class Player
{
List<Armor> equippedArmor;
List<Buffs> currentBuffs;
public Damage damageComponent;
public List<HealthBars> healthBarComponents;
}
abstract class HealthBar //can be inherited for mana or health bar
{
protected Color color;
public float percent; //0.0 - 1.0
}
When a player receives damage, I need to show a red number floating up from their head, indicating the amount of damage. This can either be implemented in HealthBar, or in Damage. It fits damage better, but then healing works in the same way, and wouldn't be called from damage. I could abstract damage into something like ChangeValue, which would change mana, health, etc in any direction, or I could use the abstract HealthBar class to show this number being changed.
I'm trying to think of a general rule that would solve this and other problems, where two classes use the same function equally. This is an oversimplified version of my classes, but it makes more sense this way.
How should I handle functions, where two classes have equal use?