1

I have successfully used strategy design pattern to for a Ducks Class and its Subtypes. Below is the diagram of relationships between different classes.

enter image description here

Now, I want to create a Factory to generate instances of different types of ducks. Should I use behavior classes (FlyBehavior and QuackBehavior) or should I use just Duck class to create a Factory class? Thanks. Your help will be appreciated.

Chuchoo
  • 823
  • 2
  • 17
  • 36
  • I guess you should create factory class with Duck class and based on some conditions return different Duck species. – vikas kumar Dec 07 '17 at 04:09
  • Generally, factories should be instantiated in the [Composition Root](https://stackoverflow.com/questions/6277771/what-is-a-composition-root-in-the-context-of-dependency-injection). – jaco0646 Dec 11 '17 at 00:51

1 Answers1

0

Between the options you gave, I would go with factory class to get duck instances on some options.

But I would suggest considering builder pattern here.

Erndob
  • 2,512
  • 20
  • 32