You have a service, which is about getting some data by a getData() method. Instead of synchronously returning the data, the method notifies (possibly later) a callback:

service.getData(callback);

The callback exposes these methods:

public interface Callback
  {
     public void notifyNoData();

     public void notifyData (Datum datum);

public void notifyDataCouldBeRetrieved (ConfirmationCallback confirmationCallback);
  }

The first two methods are obvious. When the third is called, to confirm the operation you have to call a doRetrieve() method on the ConfirmationCallback:

public interface ConfirmationCallback
  {
     public void doRetrieve();
  }


I've been playing with this design since a few time for UI design; and I'm going to blog about it. I usually refer to this as "async message style", but I'm almost sture there's a more specific name for it. Which one? Searching around it seems that there are some similarities with CPS (Continuation-Passing Style), but I'm really dubious about that (my understanding of Continuations is very different; but perhaps CPS is different than "pure" Continuations?). I've found some references to CPS, including some code samples, and some make me think this is CPS, others not (especially those dealing with variations on tail recursion or stackless implementations - perhaps they are just different scenarios than mine, perhaps the CPS is a totally different thing).

Help appreciated (biblio references too).

PS Please don't post whether you like this design or not :-) I'll be happy to later answer to comments to the blog post when it's ready. Now I just need to complete the post with the proper terminology.

--
Fabrizio Giudici - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
java.net/blog/fabriziogiudici - www.tidalwave.it/people
fabrizio.giud...@tidalwave.it

--
You received this message because you are subscribed to the Google Groups "The Java 
Posse" group.
To post to this group, send email to javaposse@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to