When designing an Aggregate, there are some rules and considerations to follow in order to get all the benefits and minimize the negative effects. Don't worry too much if you don't understand everything now; as an example, we'll show you a small application where we'll be referencing the rules we introduce you to.
First of all, what's an invariant? An invariant is a rule that must be true and consistent during code execution. For example, a stack is a LIFO (Last In, First Out) data structure that we can push items into and pop items out of. We can also ask how many items are inside of the stack; this is what's called the size of the stack. Consider a pure PHP implementation without using any specific PHP array functions such as array_pop
:
class Stack { private $data; public function __construct() { $this->data = []; } public function push($value) { $this->data[] = ...