private $title; private $content; private $publishingDate; public function __construct(PostId $postId) {/**/} // getters/setters… public function getAggregateId() {/**/} public function update($title, $content) {/**/} private function applyPostWasPublished(PostWasPublished $event) {/**/} private function applyPostWasUpdated(PostWasUpdated $event) {/**/} public static function create($title, $content) {/**/} public static function reconstituteFrom( AggregateHistory $postAggregateHistory ) {/**/} }
• aggregate history is an ordered set of events affecting particular aggregate • reconstitute aggregate’s state: ‣ create new instance of the aggregate class ‣ replay events from aggregate history on it
$postId; public $title; public $publishingDate; public function __construct(PostId $postId, $title, \DateTime $publishingDate) { $this->postId = $postId; $this->title = $title; $this->publishingDate = $publishingDate; } public function getProjectionName() { return self::PROJECTION_NAME; } public function getAggregateId() { return $this->postId; } // ... }
objects • store only facts that happened (events) • reconstitute state of aggregates from event storage • dispatch events to update projections • use projections for reading