2. この資料について
UML入門です。
UMLでよく使うクラス図と
シーケンス図に絞って説明します。
UMLには他にもユースケース図、アクティブティ図、状態図、
などなどたくさんの図があります。
C++で説明を行います。
UMLでの名前と、C++での名前を併記します。
UML : name in UML(english)/ UMLでの名前(日本語)
C++ : name in C++(english)/ C++での名前(日本語)
例)
UML : attribute/属性
C++ : member variable/メンバ変数
3. What's UML ?
Unified Modeling Language
the Unified Modeling Language (UML) is a standardized specification language for object modeling.
UML is officially defined at the Object Management Group (OMG).
ISO acceptance: OMG is pleased to announce that the UML specification
(version 1.4.2, OMG document: formal/05-04-01) is now an accepted ISO specification.
It is available from ISO as ISO/IEC 19501.
UML version 2.1.1 2007/02/03
http://www.omg.org/technology/documents/formal/uml.htm
We can dounload the UML standards.
簡単に言うと、コミュニケーションの道具。言葉と同じ。
みんなが知ってるルールで図を書けば、
伝えるのも簡単だし早い!
4. クラス図
C++ codes
ClassA class name/クラス名
class ClassA{
+field1 : int UML : attribute/属性
public:
#field2 : char C++ : member variable/メンバ変数
int filed1;
-field3 : ClassB* [可視性] [属性名] : [型]
protected:
char field2; +method1 : void UML : operation/操作
private: #method2 : int C++ : method/メソッド
ClassB* field3; -method3 : char* [可視性] [操作名] : [戻り値の型]
public:
void method1();
protected:
属性はassociation/関連を使って書くことも可能です。
int method2();
private: UML : multiplicity/多重度
char* method3(); * = 0~無限大
}; 0..1 = 0 or 1
ClassA ClassA ClassB
1 0..1
UML : visibility/可視性
- field3 : ClassB
# protected
+ public
- private
5. クラス図
C++ codes
UML : abstract method/抽象操作
class ParentClass{
C++ : 純粋仮想関数
ParentClass
int filed1;
Italic style(斜体)にする
field1
static char field2; 属性に抽象操作を持つクラス名も斜体に。
field2
virtual void method1() = 0;
UML,C++ : static/静的
int method2(){ method1
下線を引く
// ... method2
};
UML : generalization/汎化
};
C++ : inheritance(is-a)/継承
この形の矢印
<<interface>>
ChildClass
class ChildClass : public ParentClass{ IFClass
void method1(){
// ... method1
JAVAなどには
method1 method2
}; interface
method3 という概念もあります。
static void method3(){ 破線矢印で表します。
// ... C++には無いです。
}; ImprementedClass
};
method1
method3
6. クラス図
C++ codes Color
class Color {
// ... UML : aggregation/集約
}; C++ : has-a/持っている
この形の矢印
class Fruit { Fruit
Color color;
color
// ...
};
class Basket {
Fruit fruits[10]; Basket
} note/ノート
fruits
commentを
書くときは
こう書きます。
7. クラス図
Fruit Fruit composition/コンポジション =
aggregation/集約 + 以下の制限
持たれている対象(Fruit)のインスタンスは、
同時に2つ以上のクラスに属することはできない。
ほとんどの場合、コンポジション関係の2つのイ
Basket Basket
ンスタンスは生存期間が同じ。
fruit fruit
aggregation/集約 composition/コンポジション(構成?)
from UML version 2.1.1
quot;Composite aggregation is a strong form of aggregation that requires a part instance be included in at most
one composite at a time. If a composite is deleted, all of its parts are normally deleted with it. Note that a part can
(where allowed) be removed from a composite before the composite is deleted, and thus not be deleted as part of the
composite. quot;
Engine engine;
Car Engine Bus Car car;
car->Set(engine); engineインスタンスは
engine engine
Bus bus; carインスタンスで持ったら
bus->Set(engine); busインスタンスでは持てない。
9. 参考文献
Uml Distilled: A Brief Guide to the Standard Object Modeling Language
ISBN-13: 978-0321193681
Martin Fowler
UMLモデリングのエッセンス第3版
ISBN-13: 978-4798107950
↑の本の日本語版。
Design Patterns: Elements of Reusable Object-Oriented Software (Addison-
Wesley Professional Computing Series)
ISBN-13: 978-0201633610
GoF本。デザインパターンの基礎。難しい。
増補改訂版Java言語で学ぶデザインパターン入門
ISBN-13: 978-4797327038
結城浩さん著。GoF本に沿ってデザインパターンを易しく分かりやすく解説。
本資料の題材は結城さん本の序章にある「UMLについて」を参考にさせて頂きました。
また、「UMLモデリングのエッセンス第3版」でUMLについて学ばせて頂きました。
感謝申し上げます。m(_ _)m