B
- the type of the Builder itselfT
- the type being built by the build()
method of this builder.@NotThreadSafe public abstract static class AbstractLevelOfAssurance.AbstractBuilder<B extends AbstractLevelOfAssurance.AbstractBuilder<B,T>,T extends ILevelOfAssurance> extends Object
Abstract Builder pattern with self-bounding generics for ILevelOfAssurance
subtypes.
Effective Java, 2nd Ed. : Item 2: Builder Pattern.
This Builder is not thread-safe but is thread-compliant, it is supposed to be used by only one thread.
See Self-bounding generics:
http://www.artima.com/weblogs/viewpost.jsp?thread=136394
http://www.artima.com/forums/flat.jsp?forum=106&thread=136394
http://en.wikipedia.org/wiki/Covariance_and_contravariance
Modifier | Constructor and Description |
---|---|
protected |
AbstractBuilder() |
protected |
AbstractBuilder(AbstractLevelOfAssurance.AbstractBuilder<?,?> copy) |
protected |
AbstractBuilder(ILevelOfAssurance copy) |
Modifier and Type | Method and Description |
---|---|
T |
build()
Builds a new
T instance based on this Builder instance (Builder pattern for ILevelOfAssurance ). |
protected abstract T |
newInstance()
Method to be implemented by subtypes to create the right type
T of instances. |
protected abstract B |
self()
Typesafe method to avoid casting to obtain subclasses builder instances.
|
B |
type(String type) |
protected void |
validate()
Validates the state of this Builder before allowing to create new instances of the built type
T . |
B |
value(String value) |
protected AbstractBuilder()
protected AbstractBuilder(@Nonnull AbstractLevelOfAssurance.AbstractBuilder<?,?> copy)
protected AbstractBuilder(@Nonnull ILevelOfAssurance copy)
protected void validate() throws IllegalArgumentException
T
.IllegalArgumentException
- if the builder is not in a legal state allowing to proceed with the creation
of a T
instance.@Nonnull public final T build()
Builds a new T
instance based on this Builder instance (Builder pattern for ILevelOfAssurance
).
The validate()
is always called before creating a new instance through a call to the newInstance()
method.
T
instance based on this Builder instance.@Nonnull protected abstract T newInstance()
Method to be implemented by subtypes to create the right type T
of instances.
The typical implementation simply consists in writing return new MySubType(this);
T
instance based on this Builder instance.protected abstract B self()
Copyright © 2020. All Rights Reserved.