Created
August 10, 2013 17:15
-
-
Save cirpo/6201231 to your computer and use it in GitHub Desktop.
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 | |
class Cart { | |
private $status; | |
public function __construct() { | |
$this->status = new EmptyCartStatus($this); | |
} | |
public function setStatus(CartStatus $cartStatus) { | |
$this->status = $cartStatus; | |
} | |
public function checkout() { | |
$this->status->checkout(); | |
} | |
public function whatever() { | |
$this->status->whatever(); | |
} | |
} |
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 | |
class CloseCartStatus implements CartStatusInterface { | |
private $cart; | |
public function __construct(Cart $cart) { | |
$this->cart = $cart; | |
} | |
public function checkout() { | |
throw new Exception('you cannot checkout an aldready close cart'); | |
} | |
public function whatever() { | |
//logic | |
} | |
} |
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 | |
class EmptyCartStatus implements CartStatusInterface{ | |
private $cart; | |
public function __construct(Cart $cart) { | |
$this->cart = $cart; | |
} | |
public function checkout() { | |
throw new Exception('you cannot checkout an empty cart'); | |
} | |
public function whatever() { | |
//logic | |
} | |
} |
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 | |
class OpenCartStatus implements CartStatusInterface{ | |
private $cart; | |
public function __construct(Cart $cart) { | |
$this->cart = $cart; | |
} | |
public function checkout() { | |
//logica di checkout... | |
} | |
public function whatever() { | |
//logic | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment