0

I'd like to know how to translate the following line of code to a Collaboration Diagram:

Food food = new Food("abc", 123);

I know that I can call an Food's method using the following notation:

 MyStaticMethod()
----------------------> --------
                        |      |
                        | Food |
                        |      |
                        --------

being that equivalent to

Taste taste = Food.MyStaticMethod();

and

 MyInstanceMethod()
----------------------> ---------------
                        |             |
                        | food : Food |
                        |             |
                        ---------------

is equivalent to

food.MyInstanceMethod();

but how do I signal that I want to call a given constructor on Food?

Thanks

4

2 に答える 2

1

コラボレーション図では、オブジェクト間の相互作用メッセージに重点が置かれます。これは、相互作用に関与するオブジェクトと関係、および相互作用中にオブジェクト間で交換される一連のメッセージを示すために使用されます。オブジェクトの作成/破棄は、シーケンス図に示されています。

于 2010-05-29T18:50:28.807 に答える
0

静的メソッドを呼び出したいときは、通常、クラスを で表し<<metaclass>>ます。したがって、最初に示した図の答えとして、Food で MyStaticMethod という静的メソッドを呼び出すには、次のようにします。

 MyStaticMethod()
----------------------> ---------------------
                        |   <<metaclass>>   |
                        |        Food       |
                        |                   |
                        ---------------------

また、一般的にコンストラクターメソッドは で表されcreate()ます。

于 2010-05-30T20:37:43.827 に答える