Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Centralizing is not the main point of Factories - you could achieve that much easier with any kind of utility method + a private constructor. The big win of a Factory is the abstraction from concrete implementation types. Commented Jul 20, 2020 at 12:57
  • First, object creation, broadly in the abstract, is not a responsibility; responsibilities should be more domain oriented. Second, your illustration shows the client changing source code routinely, whereas I would expect the factory to change so the client doesn't have to. Commented Jul 20, 2020 at 13:40
  • @ErikEidt: I am now confused, but I think my "client" snippet is still ok because changes do not break a thing. The next software release will include new Factory instantiations. Otherwise - let's stick with your point. Even if the object instantiation is all wrapped into a factory construct, still, to instantiate types added between the last release and the new one - we still have to change somehow the client code to pass the parameter to the factory construct that will return an instance of the new type. Indeed, the point in question is always confusing... Commented Jul 20, 2020 at 17:57
  • @ErikEidt: I am assuming all the way that our goal is to achieve a situation where we will fully implement the open/closed principle. If this still breaks this principle, then how is this achieved... Commented Jul 20, 2020 at 17:58
  • 1
    "Factory method", "Factory", and "Abstract Factory" are 3 distinct sub-types addressing increasing complexity. "Factory Method" is a class method, probably static, but not a separate class. "Abstract Factory" pattern is a framework for very complex construction, the classic example is the pizza factory - multiple pizza types each with variable options. abstract class xxx does not make a "Factory" an "Abstract Factory." Look at the Builder pattern which could be used in any factory pattern. Beware over-designing due to overly-literal Open/Close interpretation. Commented Jul 20, 2020 at 18:45