'. '

WhiningBuilder

From APIDesign

(Difference between revisions)
Jump to: navigation, search
(New page: One problem with ChameleonBuilder is that the change of the return type works only for a single essential attribute. Can we modify the [[builder] pattern to work with multiple such att...)
(Multiple Throws)
Line 3: Line 3:
=== Multiple Throws ===
=== Multiple Throws ===
-
[[Java]] allows only a single return value - yet, it allows multiple '''throws''' - and throwing an [[exception]] is kind a return value as well. As the [[BuilderWithConditionalException]] it is possible use a generic type parameter to control whether the [[exception]] thrown from the '''build()''' method is [[checked exception]] or unchecked one. Let's do the same with multiple throws:
+
[[Java]] allows only a single return value - yet, it allows multiple '''throws''' - and throwing an [[exception]] is kind a return value as well. As the [[BuilderWithConditionalException]] it is possible use a generic type parameter to control whether the [[exception]] thrown from the '''build()''' method is [[checked exception]] or unchecked one. Let's do the same with multiple throws for two essential attributes (name and mimeType):
 +
 
 +
<source lang="java">
 +
public final class Builder<MissingName extends Exception,MissingMIMEType extends Exception> {
 +
 
 +
 +
 
 +
}
 +
 
[[TBD]]
[[TBD]]

Revision as of 12:32, 16 June 2016

One problem with ChameleonBuilder is that the change of the return type works only for a single essential attribute. Can we modify the [[builder] pattern to work with multiple such attributes? Another problem is the reported error - it doesn't push the user towards proper fix. Can we improve that and encourage cluelessness in users of our builders?

Multiple Throws

Java allows only a single return value - yet, it allows multiple throws - and throwing an exception is kind a return value as well. As the BuilderWithConditionalException it is possible use a generic type parameter to control whether the exception thrown from the build() method is checked exception or unchecked one. Let's do the same with multiple throws for two essential attributes (name and mimeType):

public final class Builder<MissingName extends Exception,MissingMIMEType extends Exception> {
 
 
 
}
 
 
[[TBD]]
Personal tools
buy