Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p><strong>what do they mean by family of dependent or related objects</strong></p> </blockquote> <p>Using an example from <a href="http://rads.stackoverflow.com/amzn/click/0201633612" rel="nofollow">Design Patterns</a> by the Gang of Four:</p> <ul> <li><strong>AbstractFactory</strong> (<code>WidgetFactory</code>)</li> <li><strong>ConcreteFactory</strong> (<code>MotifWidgetFactory</code>, <code>PMWidgetFactory</code>)</li> <li><strong>AbstractProduct</strong> (<code>Window</code>, <code>ScrollBar</code>)</li> <li><strong>ConcreteProduct</strong> (<code>MotifWindow</code>, <code>MotifScrollBar</code>, <code>PMWindow</code>, <code>PMScrollBar</code>)</li> </ul> <p><code>public abstract class WidgetFactory {...}</code></p> <p><code>public class MotifWidgetFactory extends WidgetFactory {...}</code></p> <p><code>public class PMWidgetFactory extends WidgetFactory {...}</code></p> <p>Let's start with the <code>MotifWidgetFactory</code>. It will produce a family of concrete products that extend or implement the abstract products. Since they are all built by the same factory, they play nice together. You cannot make a <code>PMScrollBar</code> work with a <code>MotifWindow</code>.</p> <blockquote> <p><strong>What people are doing on the name of factory pattern is below...it looks like a utility class where we are passing the class and getting the object instance.</strong></p> </blockquote> <p>Your example is a factory in that it produces an object. In this case, retrieving a singleton from a <code>Map</code>. It does not follow the "Factory Method" or "Abstract Factory" patterns and is therefore only a factory in name.</p>
 

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