Package cdc.args
Interface Factory<T>
-
- Type Parameters:
T- Type of created objects.
- All Known Implementing Classes:
AbstractFactory,AutoFactory,Singleton
public interface Factory<T>Interface dedicated to objects creation.- Author:
- Damien Carbonne
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Tcreate()Creates aTinstance.Tcreate(Args args)Creates aTinstance.List<FormalArgs>getCreationFormalArgsList()Returns a list of supported creation arguments.default ArgsgetMeta()Class<T>getObjectClass()static <E> Factory<E>singleton(E object)Creates a Singleton factory with no (empty) meta data.static <E> Factory<E>singleton(E object, Args meta)Creates a Singleton factory.static <E> Factory<E>singleton(Class<E> objectClass, E object)Creates a Singleton factory with no (empty) meta data.static <E> Factory<E>singleton(Class<E> objectClass, E object, Args meta)Creates a Singleton factory.
-
-
-
Method Detail
-
getMeta
default Args getMeta()
- Returns:
- The meta data associated to this factory.
-
getCreationFormalArgsList
List<FormalArgs> getCreationFormalArgsList()
Returns a list of supported creation arguments.This list must not be empty.
If creation does not need any arguments, a list containing FormalArgs.NO_FARGS should be returned.- Returns:
- A list of supported creation arguments.
-
create
T create(Args args)
Creates aTinstance.- Parameters:
args- The creation arguments.- Returns:
- A new
Tinstance. - Throws:
IllegalArgumentException- Whenargsis not valid.
-
create
default T create()
Creates aTinstance.Uses empty args.
- Returns:
- A new
Tinstance. - Throws:
IllegalArgumentException- When empty args is not valid.
-
singleton
static <E> Factory<E> singleton(Class<E> objectClass, E object, Args meta)
Creates a Singleton factory.- Type Parameters:
E- The created objects type.- Parameters:
objectClass- The created objects class.object- The object that will be returned when a creation is asked.meta- The meta data associated to the created factory.- Returns:
- A Factory that will always return
objectwhen a creation is asked.
-
singleton
static <E> Factory<E> singleton(Class<E> objectClass, E object)
Creates a Singleton factory with no (empty) meta data.- Type Parameters:
E- The created objects type.- Parameters:
objectClass- The created objects class.object- The object that will be returned when a creation is asked.- Returns:
- A Factory that will always return
objectwhen a creation is asked.
-
singleton
static <E> Factory<E> singleton(E object, Args meta)
Creates a Singleton factory.The class of created objects is that of
object.
Meta data can be associated to the factory.- Type Parameters:
E- The created objects type.- Parameters:
object- The object that will be returned when a creation is asked.meta- The meta data associated to the created factory.- Returns:
- A Factory that will always return
objectwhen a creation is asked.
-
singleton
static <E> Factory<E> singleton(E object)
Creates a Singleton factory with no (empty) meta data.The class of created objects is that of
object.- Type Parameters:
E- The created objects type.- Parameters:
object- The object that will be returned when a creation is asked.- Returns:
- A Factory that will always return
objectwhen a creation is asked.
-
-