View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] Re: Probable bug: no method calls with "next" & init

From: Gustaf Neumann <Gustaf.Neumann_at_wu-wien.ac.at>
Date: Mon, 5 Feb 2001 23:40:00 +0100 (CET)

>>>>> "KL" == Kristoffer Lawson <setok_at_fishpool.com> writes:

KL> Yes, maybe that would be the best option. The issue stems from
KL> the problem that I have a few different ways to create an instance
KL> (and as I can only have one constructor I must do it some other way). This
KL> is fine normally, but in this particular case a sub-class can only be
KL> created in one manner and thus it should make an instance of itself
KL> using one particular initialisation procedure of its super-class.
KL> So if you have suggestions for that, I'd like to hear them. Overriding
KL> create is one way, if nothing else.

 i have to admit, that i do not fully understand the problem.
 the following seems to satisfy your needs:

  Class GeneralClass
  Class NormalClass -superclass GeneralClass
  Class SpecialClass -superclass GeneralClass

  GeneralClass instproc init1 ....
  GeneralClass instproc init2 ....

  NormalClass instproc init ... { .... init1 ....}
  SpecialClass instproc init ... { .... init2 ....}
  

 the other approach is to make init more clever. i read a hint from
 your mail, that you want to have different constructors for different
 parameters ("overloading similar to c++"). What's wrong with a switch
 in init handling these cases:

   Class C -parameter situation
   C instproc init {} {
      next
      switch [[self] set situation] {
         green { .... init1 ....}
         red { .... init2 ....}
         default .....
      }
   }

   C c1 -situation green
   C c1 -situation red


 -gustaf