Skip to content

Instantly share code, notes, and snippets.

@nezarfadle
Last active June 16, 2016 04:23
Show Gist options
  • Save nezarfadle/782babb83e22cdc1354930656c34d6dc to your computer and use it in GitHub Desktop.
Save nezarfadle/782babb83e22cdc1354930656c34d6dc to your computer and use it in GitHub Desktop.
<?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