Multiple Constructors

A class definition can have only one collective attribute called new. However, new as a function can accept different numbers of arguments, which makes it possible to initialize a class member in different ways. For example
   student = class
             public name = "xxx xxx";
             public id = "000000";
             public age = 18;
             ...
             new = function args -> ()
                        if #args == 3
                             name = args # 1;
                             id = args # 2;
                             age = args # 3;
                        elseif #args == 2
                             name = args # 1;
                             id = args # 2;
                        else if #args == 1
                             name = args;
                        end
                   end
             end



oz 2009-12-22