You're making great progress! :) Lots of issues were already fixed since I started writing this post, but I have a few more suggestions:
2.4.1 The Write Model
public static function writeNewFrom($title, $content)
{
$post = new Post(PostId::create());
$post->recordApplyAndPublishThat(
new PostWasCreated(PostId::generate(), $title, $content)
);
}
Perhaps I'm missing something, but what's the difference between PostId::create() and PostId::generate()? I assume it should read the same in both places, but even then, wouldn't it create two different Post IDs and cause inconsistency between the created post and the event that was published?
Furthermore, may I request to change this line:
$post = new Post(PostId::create());
Into this:
$post = new static(PostId::create());
?
The class declaration may not be on the same page in the book as the named constructor (depends on font-size and PDF reader), and by using static it becomes immediately clear it's creating an instance of itself, and the person reading doesn't have to scroll back up to see where they are. Plus, you're using new static in some other places already, so I think it makes sense here too.
2.5 Event Sourcing
This store is called an eventstore.
If we were using a database table to store the state of all the blog posts and another one to
store the state..
Obviously, in terms of performance, it is expensive for an aggregate to go over its full event history
every time to reach its final state all of the time.
2.6 Wrap-up
As there are plenty of options for architecturearchitectural styles, you could getmay have gotten a bit confused in this chapter.
You're making great progress! :) Lots of issues were already fixed since I started writing this post, but I have a few more suggestions:
2.4.1 The Write Model
Perhaps I'm missing something, but what's the difference between
PostId::create()
andPostId::generate()
? I assume it should read the same in both places, but even then, wouldn't it create two differentPost
IDs and cause inconsistency between the created post and the event that was published?Furthermore, may I request to change this line:
Into this:
?
The class declaration may not be on the same page in the book as the named constructor (depends on font-size and PDF reader), and by using
static
it becomes immediately clear it's creating an instance of itself, and the person reading doesn't have to scroll back up to see where they are. Plus, you're usingnew static
in some other places already, so I think it makes sense here too.2.5 Event Sourcing
2.6 Wrap-up