[Gambas-user] How to stop "Greedy" constructors consuming parameters

Bruce bbruen at ...2308...
Sat Apr 20 03:13:15 CEST 2013


I have a deep hierarchy of classes, seven levels of specialisation so
far and likely to grow.  There are 64 classes in the hierarchy, which is
very strongly designed.

When instantiating any of these objects, the exact type to be created is
unknown, so the root class has a static "factory method" to decide and
create the correct object in the heirarchy.

All leaf classes (obviously) represent a real object in it's own right.
However, some of the intermediate classes are also real objects. All of
the classes have constructors that have two parameters, a string array
("Source") and a string ("Name") i.e.
        Public Sub _new(Source as String[], Name as String)
The intent of the constructor is to parse the Source array and set the
object property values accordingly.

This is my problem.  Each of the constructors "consumes" some of the
parameters passed according to their specific signature.  So to create
an object three levels down the hierarchy, I need to call the
constructor with 4 dummy and the two real parameters, i.e. 
        hObj = New Level3Class(Null,Null,Null,Null,Source,Name)
so the two real parameters are available to the "real" constructor in
Level3Class.
At level 4, 6 dummy and the 2 real parameters, i.e.
        hObj = New
        Level4Class(Null,Null,Null,Null,Null,Null,Source,Name)

This is becoming very painful.

Is there any way to "turn off" the way constructors consume parameters?






More information about the User mailing list