mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-03 13:37:27 +02:00
README Strategy
This commit is contained in:
16
Strategy/README.md
Normal file
16
Strategy/README.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Strategy
|
||||||
|
|
||||||
|
## Terminology:
|
||||||
|
|
||||||
|
* Context
|
||||||
|
* Strategy
|
||||||
|
* Concrete Strategy
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
To separate strategies and to enable fast switching between them. Also this pattern is a good alternative to inheritance (instead of having an abstract class that is extended).
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
* sorting a list of objects, one strategy by date, the other by id
|
||||||
|
* simplify unit testing: e.g. switching between file and in-memory storage
|
@@ -2,24 +2,6 @@
|
|||||||
|
|
||||||
namespace DesignPatterns\Strategy;
|
namespace DesignPatterns\Strategy;
|
||||||
|
|
||||||
/**
|
|
||||||
* strategy pattern
|
|
||||||
*
|
|
||||||
* Terminology:
|
|
||||||
* - Context
|
|
||||||
* - Strategy
|
|
||||||
* - Concrete Strategy
|
|
||||||
*
|
|
||||||
* Purpose:
|
|
||||||
* to separate strategies and to enable fast switching between them.
|
|
||||||
* also this pattern is a good alternative to inheritance (instead of having an abstract class that is extended)
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
* - sorting a list of objects, one strategy by date, the other by id
|
|
||||||
* - simplify unit testing: e.g. switching between file and in-memory storage
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
$elements = array(
|
$elements = array(
|
||||||
array(
|
array(
|
||||||
'id' => 2,
|
'id' => 2,
|
||||||
|
Reference in New Issue
Block a user