Interface Builder<ElementType,CreateType,BuilderType extends Builder<ElementType,CreateType,BuilderType>>

All Known Implementing Classes:
AbstractBuilder, URLBuilder

public interface Builder<ElementType,CreateType,BuilderType extends Builder<ElementType,CreateType,BuilderType>>
Basic abstraction for the builder pattern. A builder can have elements added to it, and once some number of elements have been added, can use those elements to construct an object of some sort.

Builders are meant to be used once to create an object and then thrown away, not reused.

This class is parameterized on (typically) its own type so that, if additional methods are required (for example, URLBuilder lets you set some things and add others), the exact builder subclass does not need to be exposed.

Author:
Tim Boudreau
  • Method Details

    • add

      BuilderType add(ElementType element)
      Add an element

      May throw an exception if called after create() has been called.

      Parameters:
      element - The element
      Returns:
      this, or a new builder (callers should not assume all implementations return this)
    • add

      BuilderType add(String string)
      Add an element as a string. Optional operation, may throw UnsupportedOperationException.

      May throw an exception if called after create() has been called.

      Parameters:
      element - The element as a string which will be parsed
      Returns:
      this, or a new builder (callers should not assume all implementations return this)
    • create

      CreateType create()
      Create an object. A Builder should be thrown away after a call to this method, and implementations will typically throw an exception if this is called twice.
      Returns:
      The object this builder creates, which somehow composes together the elements that were passed to it
    • build

      default CreateType build()