Howdy!
Why? Re: Re5: Constructor/Factory Orthodoxy by steves spoke to this.
For myself, if I have a bunch of classes that inherit from
a base class that provides the constructor (or at least a
default constructor), and I want "another one of these",
where I don't necessarily know exactly what package "this"
is blessed in to, I either have to do ref($this) everywhere
I do this, or just expect that $this can(new) and let new
figure it out.
Sure, if I call $obj->new, Perl may have to dredge through
@INC@ISA to find the method, where Class->new is explicit, but
that may force me (the lazy programmer) to have to discern
Class from $obj every time. If I bury that discovery in
new, I only have to do it in one place.
I'm not clear on what you mean by "more complicated and slower". Well, I can see the "slower" part, but "more
complicated"?
yours,
Michael
Update: corrected erroneous reference to @INC (where I should have said @ISA) (slaps forehead) | [reply] |
| [reply] [d/l] [select] |
| [reply] [d/l] [select] |
Howdy!
I don't see a compelling argument either way.
Assuming the situation I posit holds, the reader or user
will, of necessity, have consulted the documentation for
the modules that would, of course, speak to matters relevant
to "what can I do with this thingy". It pretty much follows
from the posited situation that the possible values of
ref($obj) are closely related in some useful manner, so
as to permit generalization. Heck, they may all have an
identical set of methods, differing only in how those
methods do stuff.
If I am in a situation where I need "another ref($obj)",
I, in my laziness, don't want to be forced to say ref($obj)
just for the sake of truth and beauty. I do not see that
having "new" take the ref() if necessary as being, per se,
a Bad Thing.
Perhaps we will have to agree to disagree.
yours,
Michael
| [reply] [d/l] [select] |