|
From: Sandro M. <naa...@gm...> - 2006-02-04 16:06:50
|
On 2/4/06, Tyler Close <ty...@wa...> wrote:
>
>
> > I suggest an incrementing counter:
> >
> > public class Counter {
> > int current;
> > public int getCurrent() {
> > return current;
> > }
> > public void add(int i) {
> > current +=3D i;
> > }
> > }
>
> The above class isn't Serializable, and so an attempt to construct an
> object will fail since the server won't be able to save the created
> instance to disk. The object also has mutable state, which needs to be
> put into a database record.
Which explains the behaviour I described in a follow-up note.
> As useless as this really is, it focuses on the core fundamentals:
> >
> > 1. web-calculus doc serialization of a class
> > 2. generating a schema from a class definition
> > 3. generating a custom stylesheet for a schema
> > 4. invoking a method via POST
> > 5. idempotency of GET and non-idempotency of POST
> > 6. how the waterken server marshals arguments for you
> >
> > These strike me as the fundamentals that need to be grasped in order
> > to do anything in the web-calculus. Thoughts?
>
> I think we need to add:
>
> 7. how the waterken server manages mutable state
>
> After that, I think we've got a good list.
>
> Perhaps the "Hello World!" example should be just that:
>
> public final class
> Hello {
> public static String
> getGreeting() { return "Hello World!"; }
> }
>
> Perhaps this example could then be mutated to:
>
> public final class
> Hello implements java.io.Serializable {
>
> private String greeting;
>
> public
> Hello(final String greeting) {
> this.greeting =3D greeting;
> }
>
> public String
> getGreeting() { return greeting; }
> }
>
> And finally, to show mutable state:
>
> public final class
> Maker implements java.io.Serializable {
>
> private String greeting;
>
> public static Hello
> make() { return new Hello(Global.create(new Maker())); }
>
> public static final class
> Hello implements java.io.Serializable {
>
> private Key scope;
>
> Hello(final Key scope) {
> this.scope =3D scope;
> }
>
> public String
> getGreeting() { return ((Maker)scope.query()).greeting; }
>
> public void
> setGreeting(final String greeting) {
> ((Maker)scope.update()).greeting =3D greeting;
> }
> }
> }
>
> Thoughts?
I think that's very good. I've seen the above pattern quite a bit, but it
looks a tad strange; some elaboration might help me understand why this
approach is taken. I'm specifically referring to the Maker pattern, the dat=
a
used in the nested class being stored in the parent class rather than as a
private variable, etc. For instance, is there a design that makes use of a
single class instead? Something like:
public static final class
Hello implements java.io.Serializable {
private Key scope;
public Hello(final String greeting) {
this.scope =3D Global.create(greeting);
}
public String
getGreeting() { return ((String)scope.query()); }
public void
setGreeting(final String greeting) {
//not sure how this should be properly updated.
// 1. wiping the record and creating a new one in its place won't work
as I believe that assigns a new random guid
// 2. scope.update() seems to implicitly assume a composite object,
rather than a base type, so this necessitates a two-class design
//scope.wipe();
//scope =3D Global.create(greeting);
}
}
I'm trying to create a design with only one class as the next logical
evolution of the above design process. If it's deficient in some way, then
it can be used as a transitional example to the Maker pattern.
Sandro
|