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.
精彩评论