简体   繁体   中英

Factory Design Pattern - Which class should I use to create a Factory

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

在此处输入图片说明

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM