void Start() { IEnemyAttacker tank = new EnemyTank(); EnemyRobot fredTheRobot = new EnemyRobot(); IEnemyAttacker adapter = new EnemyRobotAdaper(fredTheRobot); fredTheRobot.ReactToHuman("Hans"); fredTheRobot.WalkForward(); tank.AssignDriver("Frank"); tank.DriveForward(); tank.FireWeapon(); adapter.AssignDriver("Mark"); adapter.DriveForward(); adapter.FireWeapon(); }
void Start() { // そのままEnemyRobotをnewした場合 EnemyRobot fredTheRobot = new EnemyRobot(); IEnemyAttacker tank = new EnemyTank(); // アダプターパターンを利用した場合 IEnemyAttacker adapter = new EnemyRobotAdapter(fredTheRobot); Debug.Log("--------fredTheRobot--------"); fredTheRobot.ReactToHuman("Hans"); fredTheRobot.WalkForward(); Debug.Log("--------tank--------"); tank.AssignDriver("Frank"); tank.DriveForward(); tank.FireWeapon(); Debug.Log("--------adapter--------"); adapter.AssignDriver("Mark"); adapter.DriveForward(); adapter.FireWeapon(); }
public void AssignDriver(string driver) { robot.ReactToHuman(driver); }