Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's my opinion.</p> <p>First of all, the Abstract Factory pattern is not intended to be a factory of factories. The key aspect of this pattern is that there is an accessible interface with an underlying (probably inaccessible) factory implementation through which you can get accessible interfaces of (probably inaccessible) object implementations. I know, is a long nasty wordplay of how I understand some of the applicability conditions of this pattern in Gamma's book:</p> <blockquote> <ul> <li>a system should be independent of how its products are created, composed, and represented</li> <li>you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations.</li> </ul> </blockquote> <p>At the end you're getting objects, not factories.</p> <p>Second, I wouldn't make 1:1 relationships between pattern concepts and language keywords. "Abstract Factory" does not necessarily always translate to the Java <code>abstract class</code> or <code>interface</code> constructs. You can still have a regular, extendable, instantiable class that represents an "Abstract Factory" as long as you somehow guarantee that the client code is independent of the underlying factory and object implementations. This is the case of <code>java.lang.Class</code>, which is not abstract nor an interface, but does the job at hiding the parameterless constructor implementation of the type it represents through the <code>newInstance()</code> method. It's probably clearer if you use it like:</p> <pre><code>Object o = Class.forName(type).newInstance(); </code></pre> <p><code>Class</code> plays the "Abstract Factory", and <code>Object</code> plays the "Abstract Product" to the type implementation. </p> <p>Last, <code>newInstance()</code> is not a static factory method, I think because this pattern is intended to return instances of the class it is implemented on. <code>newInstance()</code> does not return instances of <code>Class</code> nor sub-<code>Class</code>es. It returns instances of the type it represents. It neither is a "Factory Method" just as Bloch states in his book.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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