开发者

abstract factory design pattern: why need to be used with singleton [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_如何学Go Closed 10 years ago.

i just dont understand why it is often used with a singleton.

thanks


The factory is the singleton. Otherwise you have to pass the factory around all over the place. Since it's not a factory you are creating, rather the factory creates the object for you, you still have good separation from the concrete object types. You only depend on the factory.


Singleton is an overused pattern, but it's supposed to be used when there should be no more than one instance of a particular class.

In the abstract factory pattern, there is usually no need for more than one factory at a time, and if there were two factories of different types operating during the client's lifetime the two types of manufactured objects might be incompatible, and come into conflict.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜