Alex Rivera | Logout

Factory Creation Methods Always Static?

Asked 2009-10-15T08:25:28.870
39

It's common place for factory classes to be static, and factory methods to be static also.

Did the GOF in the Design Patterns book ever stipulate that factories and their methods MUST be static in order to meet the strict definition of the pattern?

Is having factories+/methods static just a consequence of the pattern? state data is not normally maintained by the factory class, so they're normally static.

Edit
Report

1 Answer

7

No, factory class by default shouldn't be static. Actually, static classes are not welcomed in OOP world since they can also convey some state and therefore introduce global application state. If you need only one factory object to be present, you can control it's creation through singleton pattern.

In case of factory method - it is ok to keep it static (actually there's no other reasonable way to go :)).

answered 2009-10-15T08:33:59.897

Your Answer