ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kuiper, Arnout" <Arnout.Kui...@nl.origin-it.com>
Subject RE: Ant Principles
Date Fri, 21 Apr 2000 09:14:16 GMT
> From: Thomas Haas [mailto:thomas.haas@softwired-inc.com]
> > From: Kuiper, Arnout <Arnout.Kuiper@nl.origin-it.com>
> >
> > Nested objects
> > ==============
> >
> >   Suppose the type is Foo.
> >   1. Check if Foo(String) exists. If so, use it, and we're done.
> >   2. Check if Foo(double) exists. If so, cast String to double,
> >      use it, and we're done.
> >   3. iterate step 2 for each primitive type.
> >   4. Failure...
> 
> Random thought:
> Would a factory method instead of the constructor add value to your
> proposal?
> public static Foo create(String)
> We get the possibility of returning a subclass of Foo instead 
> of Foo itself.
> However I cannot think of a situation right now, where I 
> could use it. And
> the same effect could be achieved by using a strategie object.

When subclassing a task, and subclassing the Type of an attribute,
this might be useful. This situation is comparable with the
situation below. See below for the solution to this problem.

> > - Nested elements are added with reflection. Look for a method
> >   with the signature "void addObject(Type value)", where Object
> >   is the name of the element. An object of type Type is 
> instantiated,
> >   and we recurse on that nested element. I think addFoo is better
> >   than setFoo, because we can have multiple elements with 
> the same tag.
> 
> This implies a subclass of a task cannot use a subclass of 
> Type as Object?

Yes you can. In your subclass just declare
"void addObject(SubType value)". You might think that there are now
two methods "void addObject()", with different argument types.
Correct, but when trying to resolve the type, we use the method
Class.getDeclaredMethods(), which returns the declared methods of
the task. When no method was declared, it's parent class is searched
for the method (recursively).

This way we get the latest declared addObject() method in the
inheritance tree (with it's corresponding Type).

BTW: it is still not allowed to have two addObject() methods declared
in one class, because then it cannot be determined which type to use.

This same way can be used for the attribute setters.

So in short,

   void setXxxx(<ObjectType> value); // attributes
   void addXxxx(<ObjectType> value); // entities
   void addText(String value);       // text

still holds.

  Arnout

PS: I came also up with a solution with your proposed factory method,
but when I was finished, it was 99% identical to what Sam has
already implemented.

Mime
View raw message