Class creation

Jorge Marques Pelizzoni jorge.pelizzoni at gmail.com
Thu Jun 14 21:29:52 CEST 2012


Khadija,

You might have not noticed but there is no such thing as constructor
methods proper in Oz. The language only requires that you should
specify some method (with arguments) to be called upon creation of an
object. That is the whole point of the second argument to New, and it
can be virtually any method of your choice. So you can create as many
constructors as you see fit. For example (please pardon my Oz. It's
ages since I last wrote Oz programs):

class C
   attr someattr
   meth init1
      someattr := unit;
   end
   meth init2(V)
      someattr := {NewCell V}
   end
   meth get($)
       @someattr
   end
end

C1 = {New C init1}
C2 = {New C init2(10)}

EVEN:

C3 = {New C get(_)}

Cheers,

Jorge.

2012/6/14 Khadija EL MAHRSI <khadija.elmahrsi at gmail.com>:
> Hi,
> what you said is close to what I meant: a way to create instances of a same
> class that don't necessarily share the same number of passed arguments to
> the init method (and eventually respond differently to the passed
> arguments).
> I've also thought about some of the solutions you've listed but to be honest
> I thought it would be such a hassle when it could've been made alot easier
> by allowing something close to multiple constructors where you could have
> different initialization methods to call according to your need.
> Thanks for the reply. I just wanted to make sure I had no other choice
> before resorting to other solutions.


More information about the mozart-users mailing list