O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Properties in classes

We have talked a lot about the Dynamic type, but now, we are going to talk about something else: properties.

Use

Sometimes, you would like to be able to react to the access to an object's property. Whether this is when reading from or assigning to the property, the only way to do that is through the use of functions.

It would then be possible to use it with some code looking like this:

myObject.getValue(); //or myObject.setValue("This is my new value");

This is a non-natural way of accessing properties, and it can make the code really difficult to read, particularly if you are going to chain calls.

With properties, we will be able to define our functions setValue and getValue so that we can react to accesses to our properties. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required