Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Factories and Patterns relate?

I was just reading a thread on SO that was discussing the merits of Singleton vs. Static Classes.

Some people mentioned that pattern X appeared to be more of a 'factory' rather than a Singleton 'pattern'.

What are the differences between a 'factory' and a 'design pattern'?

like image 556
Randy Minder Avatar asked Feb 05 '10 12:02

Randy Minder


2 Answers

A "factory" is a specific design pattern: http://en.wikipedia.org/wiki/Factory_method_pattern

Similarly "singleton" is also a design pattern: http://en.wikipedia.org/wiki/Singleton_pattern

like image 178
Paolo Avatar answered Sep 19 '22 20:09

Paolo


Factories and Singletons are some of the many design pattern.

A factory pattern can be implemented as a singleton pattern that produces objects. A factory could also be an instanced class, and therefore not a singleton. Likewise, a singleton can be a factory, but it can also be something else, like a global settings manager or event registry.

like image 32
Max Shawabkeh Avatar answered Sep 18 '22 20:09

Max Shawabkeh