Constructors come short
I've been writing several classes in PHP, and recently became so uncomfortable with the inflexibility of the "constructor" method of describing instance creation that I implemented what I had previously thought of as a Smalltalk hack to handle not having access to instance variables outside instance methods. Names changed to protect the …:
class Foo
{
static function makeInstances ($args…)
{
// code that constructs and calls the initializer here
}
function initRawData ($args…)
{
// finish munging the data and put it in instvars here
}
}
I was trying to define a good constructor, and the only thing I could decide was that I didn't want to lock initialization into a single protocol, neither would suffice for the other, and neither was better than the other.
Just as with Smalltalk, there is no constructor for this class; instance creation is completely informal. Also, exactly how instance creation works is '''much''' clearer in this classes than in the other classes I've been writing. I may end up dropping constructors altogether and relying entirely on methods.
