1。可以把Effect单独抽象出来,用双向的多态模式(visitor?)实现“作用”这个问题。
class Effect{
int effectStart; //the time Effect started
int effectDuration; //the time Effect holds
int effectOn(Creature c){};
};
class Creature{
...
ArrayList effects; // The effects creature is suffering.
public void TakeEffect(Effect effect);
public void UpdateEffect(Effect effect);//need be inherited
public void Update()
{ //Iterate effects
//if(iterator.effectStart>iterator.effectDuration) iterator.remove();
//execute UpdateEffect(iterator)
}
};
如上,Effect的继承类可以自由更改Creature 的effectsList(一般是添加),而Creature的继承类可以重载UpdateEffect方法对Effect起反应。