随笔-75  评论-193  文章-5  trackbacks-0
Another option is to use implicit getters and setters. Implicit getters and setters are declared as methods, but they look like properties. The syntax for a getter is as follows:

public function get name(  ):Datatype {
}

The syntax for a setter is as follows:

public function set name(value:Datatype):void {
}

这样在代码中调用counter.count=5时相当于调用了set count(5)方法。

Counter类如下:
public class Counter {
    private var _count:uint;
    public function Counter(  ) {
        _count = 0;
    }
    public function get count(  ):uint {
        return _count;
    }
    public function set count(value:uint):void {
        if(value < 100) {
            _count = value;
        }
        else {
            throw Error(  );
        }
    }
}
posted on 2007-01-13 14:53 The Matrix 阅读(570) 评论(0)  编辑  收藏 所属分类: Flex

只有注册用户登录后才能发表评论。


网站导航:
 
<2007年1月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

随笔分类(72)

随笔档案(67)

文章分类(5)

搜索

  •  

最新评论

阅读排行榜

评论排行榜