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.");         } ...

Get Implementing Domain-Driven Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.