JaroslavTulach at 04:43, 1 October 2021 - 2021-10-01 04:43:38

←Older revision Revision as of 04:43, 1 October 2021
Line 97: Line 97:
== [[DukeScript]] Intermezzo ==
== [[DukeScript]] Intermezzo ==
-
Before we leave the [[JavaBean]] style completely, let's explore easier way to write the same [[API]]. It is provided by the [[netbeans:Html4Java]] [[API]] which is in core of [[DukeScript]]:
+
Before we leave the [[JavaBean]] style completely, let's explore easier way to write the same [[API]]. It is provided by the [[Html4Java]] [[API]] which is in core of [[DukeScript]]:
<source lang="java">
<source lang="java">
Line 170: Line 170:
== Summary ==
== Summary ==
-
When converting [[ConfigurationObject]] pattern to [[Java]] choose [[CumulativeFactory]] in case ''build'' operation on the object is the final one or [[Builder]]-like pattern in case one wants to modify the object even after calling ''build'' operation. Consider using [[netbeans:Html4Java]] @{{HTML4J|net/java/html/json|Model}} annotation once it is [https://netbeans.org/bugzilla/show_bug.cgi?id=250611 enhanced to support builder style] as well:
+
When converting [[ConfigurationObject]] pattern to [[Java]] choose [[CumulativeFactory]] in case ''build'' operation on the object is the final one or [[Builder]]-like pattern in case one wants to modify the object even after calling ''build'' operation. Consider using [[Html4Java]] @{{HTML4J|net/java/html/json|Model}} annotation once it is [https://netbeans.org/bugzilla/show_bug.cgi?id=250611 enhanced to support builder style] as well:
<source lang="java">
<source lang="java">

JaroslavTulach: /* Summary */ - 2018-05-08 16:51:35

Summary

←Older revision Revision as of 16:51, 8 May 2018
Line 170: Line 170:
== Summary ==
== Summary ==
-
When converting [[ConfigurationObject]] pattern to [[Java]] choose [[CumulativeFactory]] in case ''build'' operation on the object is the final one or [[Builder]]-like pattern in case one wants to modify the object even after calling ''build'' operation. Consider using [[netbeans:Html4Java]] @{{HTML4J|net/java/html/json|Model}} annotation once it is [https://netbeans.org/bugzilla/show_bug.cgi?id=250611 enhanced to support builder style] as well.
+
When converting [[ConfigurationObject]] pattern to [[Java]] choose [[CumulativeFactory]] in case ''build'' operation on the object is the final one or [[Builder]]-like pattern in case one wants to modify the object even after calling ''build'' operation. Consider using [[netbeans:Html4Java]] @{{HTML4J|net/java/html/json|Model}} annotation once it is [https://netbeans.org/bugzilla/show_bug.cgi?id=250611 enhanced to support builder style] as well:
 +
 
 +
<source lang="java">
 +
import net.java.html.json.Model;
 +
import net.java.html.json.Property;
 +
 
 +
@Model(className = "UpperConfig", builder = "", properties = {
 +
@Property(name = "text", type = String.class),
 +
@Property(name = "firstLetterOnly", type = boolean.class)
 +
})
 +
public final class Upper {
 +
public static String upper(UpperConfig c) {
 +
if (c.isFirstLetterOnly()) {
 +
return c.getText().substring(0, 1).toUpperCase() + c.getText().substring(1);
 +
}
 +
return c.getText().toUpperCase();
 +
}
 +
 
 +
public static void main(String... args) {
 +
String result = upper(new UpperConfig()
 +
.text("hello world!")
 +
.firstLetterOnly(true)
 +
);
 +
assert "Hello world!".equals(result);
 +
 
 +
result = upper(new UpperConfig()
 +
.text("hello world!")
 +
);
 +
assert "HELLO WORLD!".equals(result);
 +
}
 +
 
 +
}
 +
</source>
An example of using [[CumulativeFactory]] to implement [[ConfigurationObject]] can be found in the [[Bck2Brwsr]] ahead of time compiler [http://hudson.apidesign.org/job/bck2brwsr.javadoc/lastSuccessfulBuild/artifact/rt/vm/target/site/apidocs/org/apidesign/vm4brwsr/Bck2Brwsr.html javadoc].
An example of using [[CumulativeFactory]] to implement [[ConfigurationObject]] can be found in the [[Bck2Brwsr]] ahead of time compiler [http://hudson.apidesign.org/job/bck2brwsr.javadoc/lastSuccessfulBuild/artifact/rt/vm/target/site/apidocs/org/apidesign/vm4brwsr/Bck2Brwsr.html javadoc].

JaroslavTulach: /* DukeScript Intermezzo */ - 2018-05-08 16:43:09

DukeScript Intermezzo

←Older revision Revision as of 16:43, 8 May 2018
Line 113: Line 113:
return c.getText().toUpperCase();
return c.getText().toUpperCase();
}
}
 +
}
</source>
</source>

JaroslavTulach: /* DukeScript Intermezzo */ - 2015-02-23 08:47:24

DukeScript Intermezzo

←Older revision Revision as of 08:47, 23 February 2015
Line 115: Line 115:
</source>
</source>
-
[[DukeScript]] optimizes the way to write [[JSON]]-like objects and expose them as [[JavaBean]]s. By harnessing the power of [[AnnotationProcessor]]s, we save typing of tons of boilerplate code. Rather than writing the [[ConfigurationObject]] class manually we let the [[DukeScript]] processor to generate it when processing the three lines that define the '''@Model''' annotation.
+
[[DukeScript]] optimizes the way to write [[JSON]]-like objects and expose them as [[JavaBean]]s. By harnessing the power of [[AnnotationProcessor]]s, we save typing of tons of boilerplate code. Rather than writing the [[ConfigurationObject]] class manually we let the [[DukeScript]] processor to generate it when processing the three lines that define the {{HTML4J|net/java/html/json|Model}} annotation.
The client code however remains the same - e.g. while [[DukeScript]] helps us to write our [[API]] more easily, it does not (in this case) improve experience of users of our [[API]]. As there is many more users of the [[API]] than designers (usually just you), you should rather strive for optimizing user experience than making your life easier.
The client code however remains the same - e.g. while [[DukeScript]] helps us to write our [[API]] more easily, it does not (in this case) improve experience of users of our [[API]]. As there is many more users of the [[API]] than designers (usually just you), you should rather strive for optimizing user experience than making your life easier.

JaroslavTulach: /* Summary */ - 2015-02-23 08:46:25

Summary

←Older revision Revision as of 08:46, 23 February 2015
Line 169: Line 169:
== Summary ==
== Summary ==
-
When converting [[ConfigurationObject]] pattern to [[Java]] choose [[CumulativeFactory]] in case ''build'' operation on the object is the final one or [[Builder]]-like pattern in case one wants to modify the object even after calling ''build'' operation. Consider using [[netbeans:Html4Java]] ''@Model'' annotation once it is [https://netbeans.org/bugzilla/show_bug.cgi?id=250611 enhanced to support builder style] as well.
+
When converting [[ConfigurationObject]] pattern to [[Java]] choose [[CumulativeFactory]] in case ''build'' operation on the object is the final one or [[Builder]]-like pattern in case one wants to modify the object even after calling ''build'' operation. Consider using [[netbeans:Html4Java]] @{{HTML4J|net/java/html/json|Model}} annotation once it is [https://netbeans.org/bugzilla/show_bug.cgi?id=250611 enhanced to support builder style] as well.
An example of using [[CumulativeFactory]] to implement [[ConfigurationObject]] can be found in the [[Bck2Brwsr]] ahead of time compiler [http://hudson.apidesign.org/job/bck2brwsr.javadoc/lastSuccessfulBuild/artifact/rt/vm/target/site/apidocs/org/apidesign/vm4brwsr/Bck2Brwsr.html javadoc].
An example of using [[CumulativeFactory]] to implement [[ConfigurationObject]] can be found in the [[Bck2Brwsr]] ahead of time compiler [http://hudson.apidesign.org/job/bck2brwsr.javadoc/lastSuccessfulBuild/artifact/rt/vm/target/site/apidocs/org/apidesign/vm4brwsr/Bck2Brwsr.html javadoc].

JaroslavTulach: /* Summary */ - 2015-02-23 08:43:11

Summary

←Older revision Revision as of 08:43, 23 February 2015
Line 170: Line 170:
When converting [[ConfigurationObject]] pattern to [[Java]] choose [[CumulativeFactory]] in case ''build'' operation on the object is the final one or [[Builder]]-like pattern in case one wants to modify the object even after calling ''build'' operation. Consider using [[netbeans:Html4Java]] ''@Model'' annotation once it is [https://netbeans.org/bugzilla/show_bug.cgi?id=250611 enhanced to support builder style] as well.
When converting [[ConfigurationObject]] pattern to [[Java]] choose [[CumulativeFactory]] in case ''build'' operation on the object is the final one or [[Builder]]-like pattern in case one wants to modify the object even after calling ''build'' operation. Consider using [[netbeans:Html4Java]] ''@Model'' annotation once it is [https://netbeans.org/bugzilla/show_bug.cgi?id=250611 enhanced to support builder style] as well.
 +
 +
An example of using [[CumulativeFactory]] to implement [[ConfigurationObject]] can be found in the [[Bck2Brwsr]] ahead of time compiler [http://hudson.apidesign.org/job/bck2brwsr.javadoc/lastSuccessfulBuild/artifact/rt/vm/target/site/apidocs/org/apidesign/vm4brwsr/Bck2Brwsr.html javadoc].
[[Category:APIDesignPatterns]]
[[Category:APIDesignPatterns]]

JaroslavTulach: /* DukeScript Intermezzo */ - 2015-02-23 07:10:50

DukeScript Intermezzo

←Older revision Revision as of 07:10, 23 February 2015
Line 117: Line 117:
[[DukeScript]] optimizes the way to write [[JSON]]-like objects and expose them as [[JavaBean]]s. By harnessing the power of [[AnnotationProcessor]]s, we save typing of tons of boilerplate code. Rather than writing the [[ConfigurationObject]] class manually we let the [[DukeScript]] processor to generate it when processing the three lines that define the '''@Model''' annotation.
[[DukeScript]] optimizes the way to write [[JSON]]-like objects and expose them as [[JavaBean]]s. By harnessing the power of [[AnnotationProcessor]]s, we save typing of tons of boilerplate code. Rather than writing the [[ConfigurationObject]] class manually we let the [[DukeScript]] processor to generate it when processing the three lines that define the '''@Model''' annotation.
-
The client code however remains the same - e.g. while [[DukeScript]] helps us to write our [[API]] more easily, it does not (in this case) improve experience of users of our [[API]]. As there is many more users of the [[API]] than designers (usually just you), you should strive for optimizing user experience than making your life easier.
+
The client code however remains the same - e.g. while [[DukeScript]] helps us to write our [[API]] more easily, it does not (in this case) improve experience of users of our [[API]]. As there is many more users of the [[API]] than designers (usually just you), you should rather strive for optimizing user experience than making your life easier.
== [[Builder]] Approach ==
== [[Builder]] Approach ==

JaroslavTulach: /* JavaBeans like Style */ - 2015-02-23 07:08:38

JavaBeans like Style

←Older revision Revision as of 07:08, 23 February 2015
Line 55: Line 55:
== [[JavaBean]]s like Style ==
== [[JavaBean]]s like Style ==
-
[[JavaBean]] specification is popular in [[Java]] and using some familiar patterns (in this case [[GettersAndSetters]]) when designing own [[API]] will increase the [[Time To Market]] and [[cluelessness]] of users of your [[API]]. The [[JavaBean]] style for the above example would look like:
+
[[JavaBean]] specification is popular in [[Java]] and using some familiar patterns (in this case [[GettersAndSetters]]) when designing own [[API]] will shorten the [[Time To Market]] and increase acceptable [[cluelessness]] of users of your [[API]]. The [[JavaBean]] style for the above example would look like:
<source lang="java">
<source lang="java">

JaroslavTulach: /* Builder Approach */ - 2015-02-22 12:35:55

Builder Approach

←Older revision Revision as of 12:35, 22 February 2015
Line 147: Line 147:
</source>
</source>
-
All property modifying methods are type-safe and moreover by returning '''this''' from each of them we allow to chain the calls. The usage of this [[API]] then becomes comparable to the original usage of [[ConfigurationObject]] in [[JavaScript]]:
+
All property modifying methods are type-safe and moreover by returning '''this''' from each of them we allow to chain the calls. The usage of this [[API]] then becomes comparable to the original usage of [[ConfigurationObject]] in [[JavaScript]] while having the type-safe benefits of [[Java]]:
<source lang="java">
<source lang="java">

JaroslavTulach: /* Builder Approach */ - 2015-02-22 12:35:13

Builder Approach

←Older revision Revision as of 12:35, 22 February 2015
Line 147: Line 147:
</source>
</source>
-
All modification methods are type-safe and moreover by returning '''this''' from each of them we allow to chain the calls. The usage of this [[API]] then becomes comparable to the original usage of [[ConfigurationObject]] in [[JavaScript]]:
+
All property modifying methods are type-safe and moreover by returning '''this''' from each of them we allow to chain the calls. The usage of this [[API]] then becomes comparable to the original usage of [[ConfigurationObject]] in [[JavaScript]]:
<source lang="java">
<source lang="java">