2014年12月17日水曜日

開発環境

Head First Object-Oriented Analysis and Design: A Brain Friendly Guide to OOA&D (Brett McLaughlin (著)、Gary Pollice (著)、David West (著)、 O'Reilly Media)のChapter 2. Gathering Requirements: Give Them What They Want、CODE MAGNETS(No. 1142)を解いてみる。

その他参考書籍

CODE MAGNETS(No. 1142)

コード(BBEdit, Emacs)

Remote.java

public class Remote {
    private DogDoor door;
    public Remote(DogDoor door) {
        this.door = door;
    }

    public void pressButton() {
        System.out.println("Pressing the remote control button...");
        if (door.isOpen()) {
            door.close();
        } else {
            door.open();
        }
    }
}

RemoteTester.java

public class RemoteTester {
    public static void main(String[] args)
    {
        DogDoor door = new DogDoor();
        Remote remote = new Remote(door);

        remote.pressButton();
        remote.pressButton();
        remote.pressButton();
        remote.pressButton();
        remote.pressButton();
    }
}

入出力結果(Terminal)

$ jrun.sh RemoteTester
Pressing the remote control button...
The dog door opens.
Pressing the remote control button...
The dog door closes.
Pressing the remote control button...
The dog door opens.
Pressing the remote control button...
The dog door closes.
Pressing the remote control button...
The dog door opens.
$

0 コメント:

コメントを投稿