Additional Behavior

Sometimes it is beneficial to provide additional behavior on a Repository interface, besides the typical kinds presented in the previous sections. One behavior that comes in handy is to answer the count of all instances in the collection of Aggregates. You might think of this behavior as having the name count. However, since a Repository should mimic a collection as closely as possible, you might consider instead using the following method:

public interface CalendarEntryRepository {     ...     public int size(); }

Method size() is exactly what a standard java.util.Collection supplies. When using Hibernate, the implementation would work like this:

public class ...

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.