[keyword] design pattern

[pattern] Abstract factory pattern

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.

[pattern] Factory method

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.

[pattern] Don't Repeat Yourself (DRY Principle)

HOT TIP: this content is flagged as highly recommended !

Drupal code (and note I don't blame PHP here), both core and contributed, breaks the DRY principle so often, so constantly, so annoyingly repetitively, that it actually makes me (otherwise used to nicely coded object-oriented Java or C++ with model-driven support through graphical UML) feel like this: jr-banghead.gif

This web site and the OOE = Object Oriented Examples = One Of Each module were in part created to discourage further repetition of .. well nearly everything that is repeated in Drupal code, like those strings used as keys of structured arrays that have no intelligence other than documented key conventions, instead of intelligent objects.

Software Design Patterns and Anti-Patterns

This zone is by no means a complete or exhaustive list of design patterns or anti-patterns; it mentions only those I consider currently most relevant for the Webel tutorial modules, and also (especially the anti-patterns) for refactoring of Drupal core and prevailing Drupal contributed module coding habits.

Subscribe to RSS - design pattern