[uml] IFactory

Webel module:

Package/Namespace: 

UML element type:

OOE stereotypes:

Relationships (inverse)
UML Diagram
Click on the UML diagram to view it in a lightbox image viewer. You may then zoom in (or just open the image in a new web browser tab using the Download Original link to view large diagrams).

UML modelling domain:

This factory supports creation of one of each of the kinds of things one might require in any Drupal project/module, except for render objects, handled by IRenderFactory, and XHTML tags, handled by ITagFactory.

Because this factory has knowledge of the module machine name, the signatures of the creation methods are more concise than the matching constructors of the classes for some products (do not have to include the module machine name as a parameter). This is one very simple example of the value-adding a factory can offer over direct construction.

In general, factories enable one to apply policies and diagnostics across all created products in a centralised place. (This can be particularly important when one is creating persistent database entities).


Please note that the Drupal object-oriented coding standards recommend the use of factory methods returning interface products (28 Feb 2014):

Instantiation

Creating classes directly is discouraged. Instead, use a factory function that creates the appropriate object and returns it. This provides two benefits:

- It provides a layer of indirection, as the function may be written to return a different object (with the same interface) in different circumstances as appropriate.

- PHP does not allow class constructors to be chained, but does allow the return value from a function or method to be chained.

Visit also