ant-ivy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xavier Hanin" <xavier.ha...@gmail.com>
Subject Re: ModuleRevisionId factories and constructors
Date Fri, 04 May 2007 12:17:01 GMT
On 5/4/07, Gilles Scokart <gscokart@gmail.com> wrote:
> In ModuleRevisionId, is there any reason to have both factory methods and
> public constructor mixed.  I'm wondering which one should be used.  And why
> there is 2 different style (if there is any reasons).
The rationale behind the use of the two is the following one: when
arguments used to construct the object are properties of the object,
we use a constructor. When it's something different which requires
some processing to be converted in object properties, we use a static
factory method.

The problem is that we have many constructors for backward
compatiblity reason, which clutters the code. If you have ideas to
improve that, they are welcome!

Xavier

>
> Here is all the methods that exists:
>
>     public static ModuleRevisionId newInstance(String organisation, String
> name, String revision) {
>         return new ModuleRevisionId(new ModuleId(organisation, name),
> revision);
>     }
>     public static ModuleRevisionId newInstance(String organisation, String
> name, String revision, Map extraAttributes) {
>         return new ModuleRevisionId(new ModuleId(organisation, name),
> revision, extraAttributes);
>     }
>     public static ModuleRevisionId newInstance(String organisation, String
> name, String branch, String revision) {
>         return new ModuleRevisionId(new ModuleId(organisation, name),
> branch, revision);
>     }
>     public static ModuleRevisionId newInstance(String organisation, String
> name, String branch, String revision, Map extraAttributes) {
>         return new ModuleRevisionId(new ModuleId(organisation, name),
> branch, revision, extraAttributes);
>     }
>         public static ModuleRevisionId newInstance(ModuleRevisionId mrid,
> String rev) {
>                 return new ModuleRevisionId(mrid.getModuleId(),
> mrid.getBranch(), rev, mrid.getExtraAttributes());
>         }
>
>     public ModuleRevisionId(ModuleId moduleId, String revision) {
>         this(moduleId, null, revision, null);
>     }
>     public ModuleRevisionId(ModuleId moduleId, String branch, String
> revision) {
>         this(moduleId, branch, revision, null);
>     }
>     public ModuleRevisionId(ModuleId moduleId, String revision, Map
> extraAttributes) {
>         this(moduleId, null, revision, extraAttributes);
>     }
>     public ModuleRevisionId(ModuleId moduleId, String branch, String
> revision, Map extraAttributes) {
>         super(null, extraAttributes);
>         _moduleId = moduleId;
>         _branch = branch == null ?
> IvyContext.getContext().getSettings().getDefaultBranch(moduleId) : branch;
>         _revision = revision == null ? Ivy.getWorkingRevision() : revision;
>         _hash = _hashCode(); //stored for performance reasons, hashCode is
> very used in many maps
>         setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY,
> _moduleId.getOrganisation());
>         setStandardAttribute(IvyPatternHelper.MODULE_KEY,
> _moduleId.getName());
>         setStandardAttribute(IvyPatternHelper.BRANCH_KEY, _branch);
>         setStandardAttribute(IvyPatternHelper.REVISION_KEY, _revision);
>     }
>
>
> Gilles
>
>


-- 
Learn Ivy at ApacheCon: http://www.eu.apachecon.com/
Manage your dependencies with Ivy!
http://incubator.apache.org/ivy/

Mime
View raw message