secondary-constructor and the shared class in Curl 5.0

Another change to Curl since the pre-3.0 books were published is the way in which calling constructors in shared classes is handled.

In the past, Curl developers were warned that multiple inheritance from any classes which themselves had a common super-class would result in the same constructor being called twice.

At least in the current release of Curl 5.0 this is no longer the case. A class which risks being a shared class must provide a secondary-constructor. That constructor must match the signature of the default constructor but may itself have an empty code body. When the shared class is reached a second time for a constructor, the secondary constructor will be called. The class itself will be declared as a shared class.

For example:

{define-class shared ResourceX
  field constant identifier:String
  {constructor {default i:int, j:int}
    set self.identifier = {format "%s/%s", i, j}
  }
  {secondary-constructor {default i:int, j:float}
    || empty body
  }
}

Leave a Reply

You must be logged in to post a comment.