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

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

Generator (iterator protocol based)

design patterns | php
Intent
Define a (stream like) value producer
Motivation
We want to be able do define functional streams
Implementation
Any object implementing an iteration protocol (interface) can be a base for a generator.
Examples
//a generator implemented with iterators function generator($it=null, $cb=null) { static $itor; static $callback; if(!isset($itor)) ($itor = $it; $callback=$cb; } if($valid()) { $out = $callback($current); $next(); return $out; } //or if you are not sure about the type of the above callables ($valid, $next,..) if( call_user_func($valid) ) { $out = call_user_func( $callback, $current); call_user_func( $next ); return $out; } else throw( new some_exception ); }
‹ Fluent Interfaces/ Method chainingupGeneric function ›
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