Interface Factory<P extends Producible>

  • Type Parameters:
    P - the type of the produced object.

    @DomainFactory
    public interface Factory<P extends Producible>
    A factory is responsible for creating a whole, internally consistent aggregate when it is too complicated to do it in a constructor.

    A factory is part of the domain and responsible for creating some domain objects. In the business framework a factory can only create domain objects implementing Producible:

    • Aggregates through their aggregate root,
    • Value objects,
    • Domain events.

    Note that non-root entities are not produced by factories but should be created by their aggregate root.

    Being responsible for creating valid aggregates, factories may need to create their identity. This can be done from input parameters given to the factory or by using an IdentityGenerator.

    Example:

     public interface SomeFactory extends Factory<SomeAggregate> {
         SomeAggregate createFromName(String name);
     }
    
     public class SomeFactoryImpl implements SomeFactory {
         SomeAggregate createFromName(String name) {
             // create and return the aggregate
         }
     }
     
    • Method Detail

      • getProducedClass

        Class<P> getProducedClass()
        Returns the class produced by the factory.
        Returns:
        the produced class
      • create

        @Create
        default P create​(Object... args)
        Creates an object instance in a generic way, using the given arguments. How are these arguments used for creation is implementation-dependent.
        Parameters:
        args - the arguments for object creation.
        Returns:
        an instance of the class produced by the factory.