Last active
February 26, 2016 21:59
-
-
Save chukShirley/6e8cfe2f0981f549975d to your computer and use it in GitHub Desktop.
DDD sample
This file contains 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 MemberController | |
{ | |
private $memberService; | |
public function __construct(MemberService $memberService) | |
{ | |
$this->memberService = $memberService; | |
} | |
public function enrollAction() | |
{ | |
$name = $_POST['name']; | |
$country = $_POST['country']; | |
$this->memberService->enroll($name, $country); | |
} | |
} | |
class MemberService | |
{ | |
public function enroll($name, $country) | |
{ | |
$prospectiveMember = new ProspectiveMember($name, $country); | |
$prospectiveMember->enroll(); | |
$emailSender = new EmailService(); | |
$emailSender->sendConfirmation(); | |
} | |
} | |
class ProspectiveMember | |
{ | |
private $name; | |
private $country; | |
public function __construct($name, $country) | |
{ | |
$this->name = $name; | |
$this->country = $country; | |
} | |
public function enroll() | |
{ | |
$activeMember = new ActiveMember($name, $country); | |
// Apply $20 credit | |
$activeMember->setBalance(20.00); | |
return $activeMember; | |
} | |
} | |
class ActiveMember | |
{ | |
private $name; | |
private $country; | |
private $balance; | |
public function __construct($name, $country) | |
{ | |
$this->name = $name; | |
$this->country = $country; | |
} | |
public function setBalance($balance) | |
{ | |
$this->balance = $balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment