On Wed, Jan 7, 2009 at 4:34 AM, Ian Thomas <[email protected]> wrote:
> On Tue, Jan 6, 2009 at 10:53 PM, Manish Jethani
> <[email protected]> wrote:
>
>> The first enhancement I can think of is a language extension called
>> 'properties'.
>>
>>    private var _myProperty:int = 0;
>>    public function get myProperty():int
>>    {
>>      return _myProperty;
>>    }
>>    public function myProperty(value:int):void
>>    {
>>      _myProperty = value;
>>    }
>>
>> This pattern is so common, it could be a language feature.
>>
>>    public property myProperty:int = 0;
>
> Manish - why not just write:
>
> public var myProperty:int=0;
>
> It has exactly the same effect!

Oh, but it doesn't!

A public variable is different from a property. A property is really
part of a component's interface. It can be overridden by subclasses.

With a property, you can do this:

  override public function get myProperty():int
  {
    return someCondition ? customMyProperty : super.myProperty;
  }

A property can be declared as part of an interface.

 interface IMyInterface
 {
    function get myProperty():int;
    function set myProperty(value:int):void;
 }

All classes that implement IMyInterface are required to have a
read-write myProperty property.

I almost never use public or protected variables in my code, unless
it's dumb data class (like a struct in C).

Manish
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to