[jboss-dev-forums] [Design of JBossCache] - Re: JBoss Cache Options API

galder.zamarreno@jboss.com do-not-reply at jboss.com
Thu Jan 29 15:57:33 EST 2009


Why not convert all methods that can take Options to varargs?

Example:

cache.get(Fqn f, Object key, Option... o);

You can then call it with or without option, i.e.:

cache.get("a/b/c", "k");

And also like this:

Option myOption = ...
  | cache.get("a/b/c", "k", myOption);

Even better now, you can define individual Option as subsclasses/implementations of Option allowing each to carry extra parameters if needed.

For example: Let's imagine that for https://jira.jboss.org/jira/browse/JBCACHE-1470 we would like to add the cache listener class to the supress event notification. You could do something like this:

SupressEvenNotificationOption seno = ....; // SupressEvenNotificationOption implements Option
  | seno.setCacheListener(MyListener.class);
  | cache.put("a/b/c", "k", "v", seno);

This looks much cleaner to me and you avoid multiple method definitions in Cache API.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4205679#4205679

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4205679



More information about the jboss-dev-forums mailing list