Java講座

デザインパターンの章
6.1. 汎化・実現・集約
デザインパターンの説明にあたり、 汎化・実現・集約について簡単に説明します。

汎化


ソースで表現すると以下のようになります。

継承を表します。
abstract class ParentClass {
    private int field1;
    private int field2;
    
    public void methodA() {
        // :
    }
    public void methodB() {
        // :
    }
}

class ChildClass extends ParentClass {
    public void methodA() {
        // :
    }
    public void methodB() {
        // :
    }
}


実現


ソースで表現すると以下のようになります。

インターフェースの実装を表します。
interface Printable {
    void print();
    void newPage();
}

class PrintClass implements Printable {
    public void print() {
        // :
    }
    public void newPage() {
        // :
    }
}


集約


ソースで表現すると以下のようになります。

フィールドを表します。
class Employee {
    private String name;
    // :
}

class Company {
    private Employee[] employees;
    // :
}
前のページ   次のページ

当ページ・当社へのご意見やご感想があればお手数ですが「お問い合わせ」までお願いいたします。
当社への就職をお考えの方は「採用情報ページ」までお願いいたします。
C言語を学びたい方は「C言語講座」もどうぞ。