Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
 public EnemyRobotAdaper(EnemyRobot robot)
 {
     this.robot = robot;
 }