ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <pe...@apache.org>
Subject Re: Appropriate coding methodology
Date Wed, 28 Nov 2001 08:00:26 GMT
On Wed, 28 Nov 2001 01:13, Jose Alberto Fernandez wrote:
> Hi guys,
>
> 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 something like:
>
>     Ant callee  = (Ant) project.createTask("ant");
>     callee.setOwningTarget(target);
>     callee.setTaskName(getTaskName());
>     callee.setLocation(location);
>
> This code assumes that the names above will always be linked to the
> particular implementations as provided by the default .properties files. On
> other parts of the code this usage of createTask() has been considered to
> be bad and instead the encouragment has been for usages of the form:
>
>     Ant callee = new Ant(project);
>     callee.setsetOwningTarget(target);
>     callee.setTaskName(getTaskName());
>     callee.setLocation(location);
>
> 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.

However what we *should* be doing is creating new utility objects and not 
reusing tasks directly but reusing the beans.

-- 
Cheers,

Pete

--------------------------------------------------
you've made a dangerous leap right over common 
sense, like some kind of metaphysical Evil Knievel
--------------------------------------------------

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message