uml入門

9

Click here to load reader

Upload: kuniaki-igarashi

Post on 24-May-2015

21.045 views

Category:

Documents


1 download

DESCRIPTION

UML超入門です。

TRANSCRIPT

Page 1: UML入門

UML入門

2007.10.26

Kuniaki IGARASHI

http://igarashikuniaki.net/tdiary/

Page 2: UML入門

この資料について

UMLでの名前と、C++での名前を併記します。UML : name in UML(english)/ UMLでの名前(日本語)C++ : name in C++(english)/ C++での名前(日本語)例)UML : attribute/属性C++ : member variable/メンバ変数

UML入門です。UMLでよく使うクラス図とシーケンス図に絞って説明します。UMLには他にもユースケース図、アクティブティ図、状態図、などなどたくさんの図があります。C++で説明を行います。

Page 3: UML入門

What's UML ?

Unified Modeling Languagethe 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/03http://www.omg.org/technology/documents/formal/uml.htmWe can dounload the UML standards.

簡単に言うと、コミュニケーションの道具。言葉と同じ。みんなが知ってるルールで図を書けば、伝えるのも簡単だし早い!

Page 4: UML入門

クラス図ClassA

+field1 : int#field2 : char-field3 : ClassB*

+method1 : void#method2 : int-method3 : char*

UML : visibility/可視性# protected+ public- private

class name/クラス名

UML : attribute/属性C++ : member variable/メンバ変数[可視性] [属性名] : [型]

UML : operation/操作C++ : method/メソッド[可視性] [操作名] : [戻り値の型]

C++ codesclass ClassA{public:

int filed1;protected:

char field2;private:

ClassB* field3;

public:void method1();

protected:int method2();

private: char* method3();

};

ClassA ClassB1 0..1

UML : multiplicity/多重度* = 0~無限大0..1 = 0 or 1

属性はassociation/関連を使って書くことも可能です。

ClassA

- field3 : ClassB

Page 5: UML入門

クラス図

ParentClass

field1field2

method1method2

ChildClass

method1method3

C++ codesclass ParentClass{

int filed1;static char field2;virtual void method1() = 0;int method2(){

// ...};

};

class ChildClass : public ParentClass{void method1(){

// ...};static void method3(){

// ...};

};

UML : generalization/汎化C++ : inheritance(is-a)/継承この形の矢印

UML,C++ : static/静的下線を引く

UML : abstract method/抽象操作C++ : 純粋仮想関数Italic style(斜体)にする属性に抽象操作を持つクラス名も斜体に。

<<interface>>IFClass

method1method2

ImprementedClass

method1method3

JAVAなどにはinterfaceという概念もあります。破線矢印で表します。C++には無いです。

Page 6: UML入門

クラス図

Color

Fruit

color

C++ codesclass Color {

// ...};

class Fruit {Color color;// ...

};

class Basket {Fruit fruits[10];

}

UML : aggregation/集約C++ : has-a/持っているこの形の矢印

Basket

fruits

commentを書くときはこう書きます。

note/ノート

Page 7: UML入門

クラス図Fruit

Basket

fruit

aggregation/集約

Fruit

Basket

fruit

composition/コンポジション(構成?)

composition/コンポジション = aggregation/集約 + 以下の制限

持たれている対象(Fruit)のインスタンスは、同時に2つ以上のクラスに属することはできない。

ほとんどの場合、コンポジション関係の2つのインスタンスは生存期間が同じ。

EngineCar

engine

Bus

engine

Engine engine;Car car;car->Set(engine);Bus bus;bus->Set(engine);

engineインスタンスはcarインスタンスで持ったらbusインスタンスでは持てない。

from UML version 2.1.1"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. "

Page 8: UML入門

シーケンス図

UML: object /オブジェクトor actor/アクター

UML: message/メッセージC++: method- call/ メソッド呼び出し

UML,C++:return/リターン (省略可)

UML:self-call/自己呼び出し

UML:frame/フレームloop文やif文を記述

オブジェクトが対話する様子を見える化するための道具

Page 9: UML入門

参考文献Uml Distilled: A Brief Guide to the Standard Object Modeling LanguageISBN-13: 978-0321193681Martin Fowler

UMLモデリングのエッセンス第3版ISBN-13: 978-4798107950↑の本の日本語版。

Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley Professional Computing Series)ISBN-13: 978-0201633610GoF本。デザインパターンの基礎。難しい。

増補改訂版Java言語で学ぶデザインパターン入門ISBN-13: 978-4797327038結城浩さん著。GoF本に沿ってデザインパターンを易しく分かりやすく解説。

本資料の題材は結城さん本の序章にある「UMLについて」を参考にさせて頂きました。また、「UMLモデリングのエッセンス第3版」でUMLについて学ばせて頂きました。感謝申し上げます。m(_ _)m