rogp/jspp — Issue #13: Property Accessors (get/set)
Author: Ezward
Created: 2011-10-31 20:54:42+00:00
State: open

It would be great to have get/set style property accessors.

ActionScript3/ecma4 and Dart both support get/set style property accessors. This is a very simple yet expressive construct.

AS3 and Dart both implement property accessors in a way that allows classes to be created with public properties variables, where later these can then be turned to get/set accessors as needed. Contrast this to Java, where any public property is generally encased in a bean-type function - so a public property that is a variable cannot easily be wrapped later without changing all the code that uses it.

// in AS3
public class HorizontalLine {
public var left:int = 10;
public var width:int = 20;
public function get right():int { return left + width; }
}

// in Dart
public class HorizontalLine {
int left = 10;
int width = 20;
int get right() { return left + width; }
}

In either case, I can use property syntax to get right, theRight = instance.right;
If I ever need to wrap left or width with a get/set, I can do this without changing any code that uses them.