[TYPO3-50-general] FLOW3 Sample Blog Application Aggregate Roots Clarification

Robert Lemke robert at typo3.org
Tue Aug 18 11:08:22 CEST 2009


Hi Duo,

Am 18.08.2009 um 09:19 schrieb Duo Zheng:

> In the Blog Application, Blog, and Post are Aggregate Roots as they
> both have Repositories. I believe I am modeling this wrong, but is it
> correct to have Post as an Aggregate Root when Blog already is?

yes, it can be correct, depending on your needs.

The question is: do you need to find posts independently from a blog?
For example if you want to display a list of the last 10 posts  
regardless
of which blog they have been posted to, you'll need a Post Repository.

> When a Blog is deleted all its entities are deleted with it. You can't
> have a Post without a Blog so it "seems" correct for Blog to be the
> only Aggregate Root and post to be part of that Aggregate.

Correct, so the drawback of introducing a Post Repository is that posts
won't be deleted automatically if you delete a Blog and it is your
responsibility to keep the whole structure consistent.

On the other hand you don't really have a choice: you need the Post  
Repository
for finding posts independently from the blogs so you have to bite the
bullet and add some code to your Blog Repository (some untested demo  
code):

public function remove(Blog $blog) {
    foreach ($blog->getPosts() as $post) {
	   $this->postRepository->remove($post);
    }
    parent::remove($blog);
}

> I guess to clearly ask the question and getting straight to the point,
> can you have Post be an Aggregate Root by itself in one case and just
> an Entity in another?

yes. BTW, "Aggregate Roots" are always Entities (but obviously Entities
are not always Aggregate Roots).

Cheers,
robert



More information about the TYPO3-project-5_0-general mailing list