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

Generic function

design patterns | php
Intent
A high-order function/algorithm implementation
Motivation
a generic select->update->eval function with one argument, whose instances/application differ for different (argument, result) types required
Implementation
Simply cache the result into an array or other appropriate type
Examples
class algorithm { var $parameters=array(); function __construct( $select, $update, $eval) { $this->parameters['select'] = $select; $this->parameters['update'] = $update; $this->parameters['eval'] = $eval; } function run($arg) { $selections = $this->parameters['select']($arg); $updates = $this->parameters['update']($selections); return $this->parameters['eval']($updates); } } //or with more syntax, not the parametrisation function algorithm( $select, $update, $eval ) { $args = func_get_args(); $args = array_slice($input, 3); $selections = call_user_func_array( $select, $args); $updates = call_user_func_array( $update, $selections); return call_user_func_array( $eval, $updates); }
‹ Generator (iterator protocol based)upHooks ›
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