質問

Hi there I hope I am able to explain myself clear enough with this problem I have been really confused about.

I have a concrete class called UTModule, it is not subclassed at all, but it is composed of several different abstract objects (for example UTListener, UTRenderer, UTDeliverer) the instantiation of these abstract classes to concrete objects defines the behaviour of my completed UTModule object.

The question I am asking is that, every example I see for the factory design pattern is in regards to an abstract object that is subclassed, whereas my object is a concrete class who's behaviour is decided by its composition.

Am I supposed to create a factory for each of my composite abstract objects? Or just create one factory that creates my UTModule, with the correct composite objects depending on the clients request?

Thanks in advance!

役に立ちましたか?

解決

I feel like using the Abstract factory pattern is a clear solution for you. Lets take UTModule as a abstract factory class which has methods to create a Factory of the Other Objects like "UTListener, UTRenderer, UTDeliverer"

Some additional interface is required for each UTListener, UTRenderer, UTDeliverer and respective factory class for each family.

UTModule add all require method to return the factory of the family you are looking.

For More details and example please follow OODesgin

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top