• Keine Ergebnisse gefunden

Literatur PHP-Code Designprinzip PHP-Design-Pattern:Strategy

N/A
N/A
Protected

Academic year: 2022

Aktie "Literatur PHP-Code Designprinzip PHP-Design-Pattern:Strategy"

Copied!
1
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

PHP http://kohnlehome.de/php/strategy.pdf

PHP-Design-Pattern: Strategy

Designprinzip

Algorithmen kapseln und austauschbar machen durch Komposition statt Vererbung.

PHP-Code

Strategieschnittstelle

interface Strategy {

public abstract function algorithm();

}

Konkrete Strategien

class StrategyA implements Strategy{

public function algorithm() { return ’AAAAAAAAAAA’; } }

class StrategyB implements Strategy{

public function algorithm() { return ’BBBBBBBBBBB’; } }

Client

Muß bei ¨Anderung der Strategie nicht ver¨andert werden.

class Client {

private $strategy = NULL;

public function setStrategy(Strategy $s){

$this->strategy = $s;

}

public function doSomething(){

return $this->strategy->algorithm();

} }

Verwendung des Clients

Anderung der Strategie zur Laufzeit m¨¨ oglich

$client = new Client();

$client->setStrategy(new StrategyA());

echo $client->doSomething();

$client->setStrategy(new StrategyB());

echo $client->doSomething();

Literatur

[Wikipedia] http://de.wikipedia.org/wiki/Strategie_(Entwurfsmuster)

Franz Kohnle Seite 1 von 1 28. April 2016

Referenzen

ÄHNLICHE DOKUMENTE

Queues, Jobs, Events, Broadcasting, and the Scheduler Helpers and

Queues, Jobs, Events, Broadcasting, and the Scheduler Helpers and

Queues, Jobs, Events, Broadcasting, and the Scheduler Helpers and

Queues, Jobs, Events, Broadcasting, and the Scheduler Helpers and

Queues, Jobs, Events, Broadcasting, and the Scheduler Helpers and

[r]

[r]

[r]