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
  • Memoization
  • Singleton
  • Factory and Abstract Factory
  • Facade
  • Partial Evaluation

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

Strategy Pattern

design patterns | php
Intent
Select algorithms on-the-fly at runtime.
Motivation
Write different loggers
Implementation
  • a strategy is a variable whose value is a function or method
  • No need for separate classes that differ in a few well understood ways
  • Strategy objects are not a no-no, but there is no inherent need for separate classes for each strategy instance
Examples
with functions
$logger = "a_logger_function"; $logger($message);
with objects
$strategy = "a_logger_class"; $log_object = new $strategy; $log_object->log(message);
‹ StateupModels, records, databases, friends and foes ›
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