in reply to Re: Re: Constructor/Factory Orthodoxy
in thread Constructor/Factory Orthodoxy
The complaints I have are from the phase I have the most experience in - maintenance. As a maintenance programmer, I am looking for the code to be as succinct, yet as informative as possible. The key here is that I'd prefer informative over succinct.
Why is that important? It reduces the time I am required to take in order to make the changes I'm told to do safely. The key there is "safely". A maintainer very often will not know the majority of the system. The more information the original developer gives me, the more confidence I have that I know what's going on.
What does all of that matter to the points I made?
new(), by convention, is usually the instantiator. clone(), also by convention, is usually a cloner. new() is a class method, clone() an object method.
They will both return you a new object, yes. But, the two methods are not the same internally. One creates a new object from values you give it (plus possibly some defaults) and the other creates an object from the object that clone() was called upon.
This doesn't mean you can't have new() do both things. But, I've never seen a new() function that had the offending line and be a cloning method. If it doesn't do both things, you have a NO-OP that is potentially confusing to your maintainer.
It's also confusing in that other developers using your class may treat the instantiation method as a cloning method. If that were to happen, that would make my head (as your maintainer) hurt really badly.
Remember - maintenance programmers will never have the following:
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re4: Constructor/Factory Orthodoxy
by mojotoad (Monsignor) on Feb 26, 2003 at 05:13 UTC | |
by rir (Vicar) on Feb 26, 2003 at 21:58 UTC | |
by herveus (Prior) on Feb 27, 2003 at 20:16 UTC | |
by rir (Vicar) on Feb 27, 2003 at 21:56 UTC | |
by herveus (Prior) on Feb 28, 2003 at 13:06 UTC | |
| |
by dragonchild (Archbishop) on Feb 26, 2003 at 15:03 UTC | |
by steves (Curate) on Feb 27, 2003 at 05:56 UTC | |
by dragonchild (Archbishop) on Feb 27, 2003 at 14:21 UTC | |
by Abigail-II (Bishop) on Feb 27, 2003 at 14:40 UTC | |
by Abigail-II (Bishop) on Feb 26, 2003 at 22:31 UTC | |
by dragonchild (Archbishop) on Feb 27, 2003 at 14:14 UTC |