Last active
August 29, 2015 14:05
-
-
Save Bolinha1/92db4fcb7153a9fe4caf to your computer and use it in GitHub Desktop.
Strategy Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface InterfaceReajuste | |
{ | |
public function reajustar(InterfaceParcela $parcela); | |
} | |
class ReajusteMensal implements InterfaceReajuste | |
{ | |
public function reajustar(InterfaceParcela $parcela) | |
{ | |
return "sou reajuste mensal"; | |
} | |
} | |
class ReajusteBimestral implements InterfaceReajuste | |
{ | |
public function reajustar(InterfaceParcela $parcela) | |
{ | |
return "sou reajuste bimestral"; | |
} | |
} | |
interface InterfaceParcela | |
{ | |
public function setReajuste(InterfaceReajuste $reajuste); | |
public function getReajuste(); | |
} | |
class Parcela implements InterfaceParcela | |
{ | |
public function setReajuste(InterfaceReajuste $reajuste) | |
{ | |
$this->reajuste = $reajuste; | |
} | |
public function getReajuste() | |
{ | |
return $this->reajuste->reajustar($this); | |
} | |
} | |
$p = new Parcela(); | |
$p->setReajuste(new ReajusteBimestral); | |
var_dump($p->getReajuste()); | |
$p->setReajuste(new ReajusteMensal); | |
var_dump($p->getReajuste()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment