Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The whole point of a Factory is to have a <strong>configurable</strong> way to create implementation instances for interfaces. The convention to have the factory in the same package as the implementation classes it provides adds a completely <strong>unnecessary restriction you're unlikely to meet in the future</strong>. Also <strong>if the implementation returned is not the same across all contexts</strong>, it makes even less sense to have it in the same package.</p> <p>For example, imagine a service lookup factory that is shared between the client and server part of an application, which returns a <em>client side implementation</em> (which resides in a client-only package) on the client, and a <em>server side implementation</em> (in a server-only package) when called from within the server's runtime.</p> <p>Your factory may even be configurable (we do this by having a XML file which defines which implementation class to return for which interface), so the implementation classes can easily be switched, or different mappings can be used for different contexts. For example, when unit testing we use a configuration which returns mockup implementations for the interfaces (do be able to do <em>unit tests</em> that are not <em>integration tests</em>), and it would make no sense at all to require those mockup implementations to be in the same package as the factory, as they're part of the testing code rather than the runtime code.</p> <p>My recommendation:</p> <ul> <li>Don't add any package restrictions on the implmentation classes, as you don't know which implementations are used in the future, or in different contexts.</li> <li>The interfaces may be in the same package, but this restriction is also unnecessary and only makes the configuration rigid.</li> <li><strong>Configurable factories</strong> (such as a service lookup) <strong>can be reused and shared across projects</strong> when the interface/implementation mapping isn't hardcoded. This point alone justifies having the factory separated from both the interfaces and the implementation classes.</li> </ul>
    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.
    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.
    3. 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