Xavier Hanin wrote:

My idea was to distinguish constructors (I defined two actually: one with no arguments, and one with all options as parameter) from factory method which actually process the argument to find what values should be for options (the settings is not part of the attributes of DeliverOptions, it's only used to give default values to the actual attributes). Another thing is that factory
methods have the advantage to be more flexible (as explained in the
excellent "Effective Java Programming" you've certainly read). But in this
case I don't see how it could really help, so if several people prefer
constructor, I'll go with it, no problem.

My main concern for this type of thing is:

1) you introduce dependencies into another component (IvySettings for instance) 2) introducing this method, basically means that your class is final and inheriting it is not an option at all.


Overall in this specific case dependencies and constraints about the model are introduced while you get no benefit in return. Indeed a DeliverOptions is actually created when you deliver...which means you do it only once in Ivy class.

I'm not sure to see what you mean. If I provide an IvySettings object, I can have good default values for my attributes. Otherwise I can't, for the cache for example. So does it mean I should avoid the empty constructor to be sure
a DeliverOptions won't ever be badly set?
As long as the contract is clearly established, to me that's pretty much fine...
After all that's what the bean and dependency injection is about

And I'm no real fan to full constructor injection because this is unreadable and people tend to stack all possible properties which becomes a nightmare when most of them are the same type, it's unreadable and error prone. In general arguments in the constructors are the 'critically needed' one and maybe another one or 2 constructors with 1 or 2 additional arguments as a helper.

The problem you're having with the cache is because the cache is not fully abstracted (or at the very least the 'repository) all while it should be totally transparent to most objects...well that would be a pain to fix all that but there's no reason to actually have the logic deported everywhere and force you to pass the cache reference everywhere.

-- stephane


Reply via email to