Note that there are some explanatory texts on larger screens.

plurals
  1. PODesign Patterns: Abstract Factory vs Factory Method
    primarykey
    data
    text
    <p><em>Note: Questions are at the end of the post.</em></p> <p>I have read the other stackoverflow threads regarding <strong>Abstract Factory vs Factory Method</strong>. I understand the intent of each pattern. However, I am not clear on the definition.</p> <blockquote> <p>Factory Method defines an interface for creating an object, but lets subclasses decide which of those to instantiate. A factory method lets classes defer instantiation to subclasses.</p> <p>By contrast, an Abstract Factory provides an interface for creating families of related or dependent objects without specifying their concrete classes.</p> </blockquote> <p>-<a href="https://stackoverflow.com/questions/1001767/design-patterns-factory-vs-abstract-factory">John Feminella</a></p> <p>The <strong>Abstract Factory</strong> looks very similar to the <strong>Factory Method</strong>. I have drawn a few UML classes to illustrate my point. </p> <p>Note: </p> <ul> <li>The diagram are from <em>www.yuml.com</em> so they are not perfectly oriented. But its a free service :).</li> <li>The diagrams may not be perfect. I am still learning the <strong>GoF</strong> design patterns.</li> </ul> <p><strong>Factory Method:</strong></p> <p><img src="https://i.stack.imgur.com/69jJo.jpg" alt="Factory Method"></p> <p><strong>Abstract Factory (only 1 member):</strong></p> <p><img src="https://i.stack.imgur.com/BQOzX.jpg7866ef51" alt="Abstract Factory (only 1 member)"></p> <p><strong>Abstract Factory (more members):</strong></p> <p><img src="https://i.stack.imgur.com/yMP7a.jpg" alt="alt text"></p> <p><strong>Questions:</strong></p> <ol> <li>If the <strong>Abstract Factory</strong> has only one creator and one product, is it still the <strong>Abstract Factory</strong> pattern? <em>(an interface for creating familes)</em></li> <li>Can the <strong>Factory Method</strong> concrete creator be created from an Interface or does it have to be from a class? <em>(classes defer instantiations to subclasses)</em></li> <li>If the Abstract Factory can have only one creator and one product, is the only difference between the <strong>Abstract Factory</strong> and the <strong>Factory Method</strong> that the creator for the former is an Interface and the creator for the latter is a Class?</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload