ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jose Alberto Fernandez" <>
Subject Re: Appropriate coding methodology
Date Wed, 28 Nov 2001 09:48:25 GMT
From: "Peter Donald" <>

> On Wed, 28 Nov 2001 01:13, Jose Alberto Fernandez wrote:
> > While going through the code and taking a look at what Erik was saying
> > about the behavior of <ant> I noticed that in several parts of that code we
> > use the following pattern:
> >
> >     Property p = (Property) project.createTask("property");
> >     p.setName(...);
> >     p.setValue(...);
> > [...]
> > or:
> >
> >     Property p = new Property(project);
> >     ...
> >
> > which is inmune to task name manipulation. You get an object of the class
> > you asked for.
> Both are equally bad ;)
> Project.createTask() perhaps less so as it relies on the container to 
> instantiate tasks and if we ever need to call extra methods in the task 
> lifecycle then the container will do it transparently.

Actually, what really made me bring this up was the use of Property in amy of this 
two ways as oppose to using the APIs in Project directly. Using the task will
preserve inmutability. Using Project APIs allows people to break them.

> However what we *should* be doing is creating new utility objects and not 
> reusing tasks directly but reusing the beans.
 Interesting point. The thing is that the tasks are so close to the beans that really
seem like a lot of redesign work for very little. We could have more something like:

    Task Task.createAuxiliaryTask(Class taskClass)

(1) Instead of passing the element name one passes the actual class implementation
one needs to use. This guarantees that at least the cast will work since you will be on the
classloader. Which is not guaranteed otherwise when using Project.createTask().

(2) As a method in Task, it will take care of all the initialization stuff including
setting the proyect, target, taskName, etc. Which is now being done over and
over in the code, with all the problems repeated code can bring.

Then we need to go thru all the tasks on the project and fix them ALL. :-)

Jose Alberto

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message