2nd - create a second constructor and use polymorphism to reduce the number of arguments., AdminiScott goes:
ie:
foo (argument1, argument2, ... argumentN)
foo (argument1, argument2) { foo(argument1,argument2, argument3 = null; argument4 = null; ... argumentN = null)) };
2) Incorrect. In Oracle 8 there is one constructor, which takes all of the object's members as arguments. This is required as you may not set default values for arguments in the constructor. The workaround is to create static factory methods (NOT constructors) that internally create default values and call the system constructor with all of the attributes set appropriately.What's the diff, exactly?
Does it apply to all OO languages, or only those with a "system constructor"(*)?
(I realise that you guys were talking about PL/SQL specifically, where that applies, but I thought this bears discussion in more general "philosophical" terms.)
Aren't all constructors, basically, commands to a class -- "gimme an instance of yourself"? I mean, wouldn't the principle of encapsulation argue for putting constructor code in the class definition(**), rather than as "free-floating" functions on some "system"(***) level?
To sum up, isn't a "static" (or "class") method that returns a new instance -- a "factory" method, if you will -- what a constructor, on the most fundamental level, IS?
As you've all no doubt discerned by now, I think so; and furthermore, I think the language syntax should reflect that -- something like "MyClass aNewObject = MyClass.makeAnInstance(foo, bar...);" -- no silly free-floating "new" and crap; just an order to the relevant entity, the class, to provide an object instance.
Isn't this much "cleaner" and more logical than the alternative? If not, why not? (BTW, no prizes for guessing which language works exactly that way. :-)
(*): As exemplified by the C++ / Java keyword "new", I suppose.
(**): And AFAIK, most OO languages -- C++ and Java among them -- do exactly that.
(***): Which would be what "new" looks like -- and which makes it a counter-intuitive "not-very-OO-feeling" aberration, IMnshO.
P.S: Yes, I *think* I see one possible practical difference, where a "factory method" differs from a constructor in how you code and use it; will hafta check that out before I talk any more about it.