Interface Factory<I>

Type Parameters:
I - the contextual instance type
All Superinterfaces:
Aggregate, Constable
All Known Implementing Classes:
Constant

public interface Factory<I> extends Aggregate, Constable
A source of (normally new) contextual instances.
Author:
Laird Nelson
See Also:
  • Method Details

    • create

      I create(Creation<I> creation)
      Returns a (normally new) contextual instance, which may be null.
      Parameters:
      creation - a Creation; may be null
      Returns:
      a contextual instance, which may be null
      See Also:
    • describeConstable

      default Optional<? extends ConstantDesc> describeConstable()
      Returns an Optional containing the nominal descriptor for this instance, if one can be constructed, or an empty Optional if one cannot be constructed.

      The default implementation of this method returns an Optional that contains a dynamic constant representing an invocation of the implementation's constructor that takes no arguments. The resolution of this dynamic constant is undefined if the implementation does not declare such a constructor.

      Specified by:
      describeConstable in interface Constable
      Returns:
      an Optional containing the nominal descriptor for this instance, if one can be constructed, or an empty Optional if one cannot be constructed
      Idempotency:
      This method is neither idempotent nor deterministic.
      Thread Safety:
      This method is safe for concurrent use by multiple threads.
    • destroy

      default void destroy(I i, Destruction creation)
      Destroys the supplied contextual instance.

      The default implementation of this method closes the supplied contextual instance if it is an instance of AutoCloseable, and closes the supplied Destruction if it is non-null.

      Parameters:
      i - the contextual instance to destroy; may be null in which case no action must be taken
      creation - the object supplied to the create(Creation) method represented here as a Destruction; may be null; must have an idempotent close() method
      See Also:
    • destroys

      default boolean destroys()
      Returns true if this Factory implementation destroys its created contextual instances in some way, or false if it does not.

      The default implementation of this method returns true.

      Overrides of this method must be idempotent and return a determinate value.

      Returns:
      true if this Factory implementation destroys its created contextual instances in some way; false otherwise
      See Also:
    • singleton

      default I singleton()
      Returns the sole contextual instance of this Factory's type, if there is one, or null in the very common case that there is not.

      The default implementation of this method returns null.

      Overrides of this method should not call create(Creation).

      Overrides of this method must be idempotent and must return a determinate value.

      Returns:
      the sole contextual instance of this Factory's type, or (commonly) null