Identifying Development Patterns – Notes

Talk by William Patton 05/12/2021. This was a general and informative discussion of design patterns with emphasis on common patterns used in WordPress.

Presentation slides.

My cryptic notes follow:

Principles:

  • DRY
  • SOLID

Most common WordPress patterns:

  • Singleton
  • Observer
  • Facade

WordPress mostly uses Singleton.

The elements of this talk are based on this book: Design Patterns: Elements of Reusable Object oriented Software

Most used patterns in WordPress space:

- Creational

  — Factory Method

  — Singleton

- Structural

  — Adaptor

  — Decorator

  — Facade

- Behavioral

  — Observer

Singleton

  — ensures only a single instance of object exists

  — provides single, global access

Is it an anti pattern? Does two things…

Singleton contains the following methods:

  • private static instance
  • private constructor
  • private static get instance to access the instance

Factory

Accepts input and returns an object instance.

Adapter - sits between client code and data provider. Translates the calls.

Decorator - Adds functionality to objects that preserves the base object.

Facade - Also called a wrapper. 

Observer - watches another object for when it changes and may do something based on the change.

Action and filters are observers. All filters are actions.

Anti Patterns:

  • Spaghetti code - tangled, messy, difficult to understand code.
  • Ravioli Code - objects are neat but don’t make sense together
  • Lasagna Code - neatly arranged but must adjust all layer
  • Lava flow/dead code - nobody knows what it does
  • Gold plating - against YAGNI - You Aren't Going to Need It - building things that are not needed.
  • The Blob or God Class - too powerful and does too many things
  • The Golden Hammer - Use to try and fix all problems
  • Reinventing the wheel - never assume the problem is unique - prove it if you think you need to.
Scroll to Top