3

While i was going through the book Head first design pattern i found that "Abstract factory relies on object composition: object creation is implemented in methods exposed in the factory interface" in the abstract factory chapter. My doubt here is how come Abstract factory relies on object composition?

if i will take the example in wikipedia then GUIFactory is an interface and WinFactory implements GUIFactory. Then how Abstract factory uses composition. Thanks in advance.

4

2 に答える 2

3

抽象ファクトリがクライアントの構成を記述し、その意味でオブジェクトの構成に依存していることを意味していると思います。

別の例を挙げると、抽象ファクトリは、などBodyCreatorのメソッドを定義しますcreateArm。具象ファクトリはおよびです。それらは複合「本体」を作成するためのすべての要素を生成するため、クライアントはこれらのさまざまなメソッドを呼び出して 1 つを構成できますが、正確にどのタイプの本体を構成しているかを知る必要はありません。ウィキペディアの例のように、GUIFactory は GUI がどの要素で構成されているかを説明します。createLegcreateHeadDinosaurCreatorHumanCreator

より明確にするために CheckBox createCheckBox()、 IMO:TextField createTextField()などのメソッドをさらに追加する必要があります。

しかし、ええ、おそらく「依存」という言葉は最良の選択ではありませんでした。

于 2013-04-22T13:04:21.837 に答える