in reply to simple OO constructor
Since the point of an object is to hold varying internal state, creating an object with "new" that has no internal state almost certainly means that the object is not yet "initialized" and thus does not yet represent a valid object. (I can think of a few rare exceptions, but those are exactly that, rare.)
So, this "simple constructor" is nothing more than an interesting sequence of code, but in practical use, practically worthless.
In perlboot, I even argue that constructors shouldn't simply be called "new", since almost any real constructor will require some sort of state that cannot be determined without the use of parameters, and naming the method to match the intent of the parameters makes it somewhat clearer. As a practical famous example, note the constructor for DBI is called connect and not new. There's no way to create a "new DBI object". Only a connected one, one that has purpose and internal state and can be used with other calls. This is a very good model to follow.
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(dws)Re: Re: simple OO constructor
by dws (Chancellor) on Sep 23, 2001 at 22:07 UTC | |
|
Re: Re: simple OO constructor
by nothingmuch (Priest) on Feb 23, 2004 at 10:30 UTC |