Created
July 27, 2020 16:20
-
-
Save OliverMensahDev/30aecb1c2ed4830e27336f58956fcdbd 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 | |
//Not meant to be extended from. | |
final class Service | |
{ | |
//All properties are immutable | |
private $properties; | |
//All arguments are required. Don’t inject contextual information; make the service reusable. Dependencies are actual dependencies, not service locators. | |
public function __construct($dependencies, $configurationValues) | |
{ | |
// Only assign arguments to properties. | |
} | |
public function commandMethod($input, $context): void | |
{ | |
// Pass data relevant to the job, plus contextual information (current time, current user, etc.). Validate input arguments. Perform the task. Produce side effects. | |
} | |
public function queryMethod($input, $context): returnType | |
{ | |
//Validate input arguments. Produce no side effects, only return information. | |
} | |
} | |
//Not meant to be extended from. | |
final class Entity | |
{ | |
//Properties can be mutable. | |
private $properties; | |
private array $events = []; | |
private function __construct() | |
{ | |
} | |
// Use named constructors as meaningful ways of instantiating the object. | |
public static function namedConstructor($values) | |
{ | |
//Validate arguments. Instantiate a new copy. Assign arguments to properties. Record domain event(s). | |
} | |
//Pass data relevant to the job, plus contextual information (current time, current user, etc.). | |
public function commandMethod($input, $context): void | |
{ | |
// Validate input arguments. Validate state transitions. Record domain events. | |
} | |
// Limit the number of query methods exposing state | |
public function queryMethod(): returnType | |
{ | |
// ... | |
} | |
public function releaseEvents(): array | |
{ | |
// Return recorded domain events. | |
} | |
} | |
//Not meant to be extended from. | |
final class ValueObject | |
{ | |
//All properties are immutable. | |
private $properties; | |
private function __construct() | |
{ | |
} | |
//Named constructors as meaningful ways of instantiating the object. | |
public static function namedConstructor($values) | |
{ | |
// Validate arguments. Instantiate a new copy. Assign arguments to properties. Record domain event(s). | |
} | |
// Use declarative names for modifiers (e.g. with…()) | |
public function modifier($input): ValueObject | |
{ | |
//Return a modified copy of the original. | |
} | |
// Limit the number of query methods | |
public function queryMethod(): returnType | |
{ | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment