GlobalTank和AllyTank继承自Tank
Tank::refresh()
public override function refresh():void {
refreshPosition();
refreshBullets();
refreshAttackPeriodCounter();
}
GlobalTank::refresh()
public override function refresh():void {
refreshPosition();
refreshBullets();
if (Math.random() * 10 < 1) {
sendBullet();
}
refreshAttackPeriodCounter();
}
AllyTank::refresh()
public override function refresh():void {
refreshPosition();
refreshGlobalPosition();
refreshBullets();
refreshAttackPeriodCounter();
}
想在这些坦克的每次更新时, 调用新方法refreshAttackPeriodCounter(), 便在它们的refresh()方法中都添加了一边
martin fowler的说法是move method+move field, 来构建一个新类
我这里用不到move fields
考虑把坦克refresh()中通用(从Tank父类继承)的行为封装到一个refreshCommonThings(), 其他行为封装到refreshSpecificThings(), 子类有不同的行为再去覆盖
现在正在给refreshCommonThings和refreshSpecificThings这两个方法想个正经的名字