2012年11月20日火曜日

クラス図のおさらい

初級プログラマのMOTIです。
中級を目指して勉強中です・・。
何か間違いやアドバイスなどがありましたら教えてください。

今日はクラス図のおさらいをします。
ちょっと知ってると読めるし読めると便利です。
 
クラスの関連
Uses:クラスAがクラスBを使用する。


Creates:クラスCがクラスDを生成する。



Notifies:クラスEがクラスFに通知する。



クラス図の描き方
クラス図の描き方 図のソース(dot)
 アクセス修飾子の表現
+ public:どこからでもアクセス可能
- private:クラス内からアクセス可能
# protected:同一パッケージ内、サブクラスからアクセス可能
~ default:同一パッケージ内からアクセス可能

継承の表現(図の左上)
extendsは実線と矢印で表します。
矢印は子クラスから伸び、親クラスを指します。

インタフェースの表現(図の右上2つ)
implementsは点線と矢印で表します。
矢印は実装クラスから伸び、インターフェースを指します。

集約の表現(図の左下)
Aggregationはひし形◇と実線と矢印で表します。
インスタンスを使ってるクラス側にひし形をつけ、矢印を伸ばし、クラスを指します。

上記の事を覚えていれば
クラス図はなんとなく読めると思います。


余談ですが、クラス図はdot言語で作りました。(手で書くなって言わないで^-^;)
digraph g {
    edge[arrowhead="vee"]
    node1 [
    shape = record,
    fontname="MS UI Gothic"
    label = "{スーパークラス| + フィールドA\l- フィールドB\l# フィールドC\l~ フィールドD|+ メソッドA\l+ メソッドB }"];
    node2 [
    shape = record,
    fontname="MS UI Gothic"
    label = "{サブクラス|クラスA | + メソッドB\l+ メソッドC\l+ メソッドD\l+ メソッドF}"];
    node3 [
    shape = record,
    fontname="MS UI Gothic"
    label = "{インタフェース| | + メソッドC}"];
    node4 [
    shape = record,
    fontname="MS UI Gothic"
    label = "{インタフェース| |+ メソッドD}"];
    node5 [
    shape = record,
    fontname="MS UI Gothic"
    label = "{クラスA| |+ メソッドE}"];
   
    node6 [
    style = filled, color = "#336666", fillcolor = "#CC9999"
    shape = record,
    fontname="MS UI Gothic"
    label = "{クラス名|変数|メソッド}"];
   
    node1 -> node2[dir=back,label = "extends"];
    node2 -> node3[style=dotted,label = "\n\n Implements"];
    node2 -> node4[style=dotted];
    node5 -> node2[arrowhead="odiamond",dir="both",label = "Aggregation"];
    node6 -> node2[color=white];
    {rank = same; node1; node3;node4}
    {rank = same; node2; node5;node6}
}

0 件のコメント:

コメントを投稿









ロリポップ!なら月々105円から

WordPress、MovableTypeなどの簡単インストール、

アクセス解析、ウェブメーラーが標準装備!






プロペシア