Class creation

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


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;
   meth init2(V)
      someattr := {NewCell V}
   meth get($)

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


C3 = {New C get(_)}



2012/6/14 Khadija EL MAHRSI <khadija.elmahrsi at>:
> 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