2015年1月5日月曜日

開発環境

Head First Object-Oriented Analysis and Design: A Brain Friendly Guide to OOA&D (Brett McLaughlin (著)、 Gary Pollice (著)、 David West (著) 、 O'Reilly Media)のChapter 5. Good Design = Flexible Software: Nothing Ever Stays the Same、SHARPEN YOUR PENCIL(No. 2656)を解いてみる。

その他参考書籍

SHARPEN YOUR PENCIL(No. 2656)

コード(BBEdit, Emacs)

Instrument.java

public class Instrument {
    private String serialNumber;
    private double price;

    public Instrument(String serialNumber, double price) {
        this.serialNumber = serialNumber;
        this.price = price;
    }

    public String getSerialNumber() {
        return serialNumber;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(float newPrice) {
        this.price = newPrice;
    }
}

Guitar.java

public class Guitar extends Instrument {
    private GuitarSpec spec;

    public Guitar(String serialNumber, double price, GuitarSpec spec) {
        super(serialNumber, price);
        this.spec = spec;
    }

    public GuitarSpec getSpec() {
        return spec;
    }
}

Mandolins.java

public class Mandolins extends Instrument {

    public Mandolins(String serialNumber, double price) {
        super(serialNumber, price);
    }
}

入出力結果(Terminal)

$ javac Instrument.java
$ javac Guitar.java
$ javac Mandolins.java
$

0 コメント:

コメントを投稿