greggles

Topics

programming

php drupal scheme scheming macros design patterns da la

design

design css

random thoughts

scribbles

alter ego

other me 'em that link us my space me linked in

Collections

Programmable web
PHP design patterns

PHP Design Patterns

  • A catalogue of php design pattern shorts
    • Accumulator passing
    • Closure
    • Control abstraction
    • Coroutines (generator based)
    • Dynamic dispatch
    • Dynamic loading
    • Facade
    • Factory and Abstract Factory
    • Fluent Interfaces/ Method chaining
    • Generator (iterator protocol based)
    • Generic function
    • Hooks
    • Interpreter
    • Iterator (based on protocol method)
    • Lazy evaluation
    • Memoization
    • Nested scope
    • Observer
    • Partial Evaluation
    • Protocol method
    • Proxy
    • Singleton
    • State
    • Strategy Pattern
  • Models, records, databases, friends and foes

Similar things

  • Learning lessons from Lisp or patterns and languages in PHP
  • Emulating closures in PHP
  • Some ways to use saved state with closures in php
  • Scoped php functions or more ways to abuse php
  • PHP Design Patterns
  • Strategy Pattern
  • Memoization
  • Singleton
  • Factory and Abstract Factory
  • Facade

Home » PHP Design Patterns » A catalogue of php design pattern shorts

Observer

design patterns | php
Intent
When an object changes, notify all interested parties
Motivation
events, synchronisation, ...
Implementation
Use hooks pattern at and after to implement the observer
No implementation needed in the Subject class
Example
//initialisation $hs = new hooks(); $observer = new interested_party(); $change_method = array($object, 'setter'); //setup change point(can be done externally from $change method) $hs->at('change', $change_method); //express interest $hs->after('change', array($obesrver, 'callback')); $hs->run($arg);
Note
The precise implementation of the hooks may differ, depending on functionality, abstraction, sugar, ... Have a look at the drupal hooks as well.
‹ Nested scopeupPartial Evaluation ›
printer-friendly version | add new comment
Home » PHP Design Patterns » A catalogue of php design pattern shorts

dikini.net

spreading confusion by accident since 1970