Last active
June 16, 2016 04:23
-
-
Save nezarfadle/782babb83e22cdc1354930656c34d6dc to your computer and use it in GitHub Desktop.
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 Author | |
{ | |
private $id, $membership, $posts = []; | |
// Pseudo code 1 | |
public function __construct($id, $membership, $posts) | |
{ | |
$this->id = $id; | |
$this->membership = $membership; | |
$this->posts = $posts; | |
} | |
public function createNewPost($id, $title, $content) | |
{ | |
// Golden Membership | |
if( count($this->posts) >= 1000000) throw new Exception("Exceed Membership limitation"); | |
// Silver Membership | |
if( count($this->posts) >= 500000) throw new Exception("Exceed Membership limitation"); | |
// Bronze Membership | |
if( count($this->posts) >= 300000) throw new Exception("Exceed Membership limitation"); | |
$post = new Post( $id, $title, $content); | |
return PostCreatedEvent($post); | |
} | |
// Pseudo code 2 | |
public function __construct($id, $membership) | |
{ | |
$this->id = $id; | |
$this->membership = $membership; | |
} | |
public function createNewPost($id, $title, $content, ExceedMembershipLimitation $specification) | |
{ | |
if( $specification->isSatisfiedBy( $this->id, $this->membership ) ) | |
{ | |
throw new Exception("Exceed Membership limitation"); | |
} | |
$post = new Post( $id, $title, $content); | |
return PostCreatedEvent($post); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment