Skip to content

Instantly share code, notes, and snippets.

@chukShirley
Last active February 26, 2016 21:59
Show Gist options
  • Save chukShirley/6e8cfe2f0981f549975d to your computer and use it in GitHub Desktop.
Save chukShirley/6e8cfe2f0981f549975d to your computer and use it in GitHub Desktop.
DDD sample
<?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