O'Reilly logo

Implementing Domain-Driven Design by Vaughn Vernon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Discussion Instances

Look at the Factory Method on Forum. It has the same motivation and very similar implementation as the one on Calendar, so there is no need to dive into great detail on it. Yet, there is an additional advantage of using the Factory Method here, as the team demonstrates.

Consider the Language-specific startDiscussion() Factory Method on Forum:

package com.saasovation.collaboration.domain.model.forum; public class Forum extends Entity  {     ...     public Discussion startDiscussion(             DiscussionId aDiscussionId,             Author anAuthor,             String aSubject) {         if (this.isClosed()) {             throw new IllegalStateException("Forum is closed.");         } ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required