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

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 ...

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