|
|
Factory methods |
Problem: If many instances of the expression new C(...) are sprinkled across a program we have very strong bindings to creation of C - as opposed to an alternative class D It is sometimes awkward to program adequate constructors because we cannot chose good name for them, and we cannot always control the parameters of constructors Solution: Create objects via one or more factory methods - typically class methods |
There exist related object-oriented design patterns called Factory Method and Abstract Factory, both of which involve inheritance |