[Mulgara-general] Mulgara API's
Paul Gearon
gearon at ieee.org
Tue Feb 26 06:49:08 UTC 2008
On Tue, Feb 26, 2008 at 12:26 AM, Life is hard, and then you die
<ronald at innovation.ch> wrote:
> Another option is to use generics, something along the lines of
>
> public interface Command<T> {
> public T execute(Connection conn)
> }
>
> public class Query implements Command<Answer> {
> public Answer execute(Connection conn) ...
> }
>
> public interface Connection {
> public <T> T execute(Command<T> cmd)
> }
>
> This avoid the multiple execute() variants, and works better if the
> code uses something like
>
> Comand cmd = ...
> ...
> Object res = con.execute(cmd)
>
> as it doesn't have to try and coerce a String to an Answer or
> something.
This is true, and you're not the first to mention it (Andrae beat
you). I just didn't think of it at the time (blame it on lack of
sleep).
However, since there are only three patterns, then generics don't
really save me much. They would be more extensible, but (a) I don't
think we need many more commands, and (b) using generics would require
significantly more editing (ie. take me more time). So I didn't see
them saving me anything. The only reason I'd be tempted to use them
would be to avoid the cast, as you say.
Paul
More information about the Mulgara-general
mailing list