by vlado on Tue, 2006-07-25 08:17
- 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);