I use implicit getter/setters all the time when it involves a single property 
of an object:
width, height, visible, etc..

I use explicit getter/setters when one or more parameters are required:
getItemAt(index), setSize(w, h)

Implict getter/setters are also invoked before the constructor, which can come 
in handy if you want to set values using 
attachMovie's initObject.

This will invoke the implicit width and height methods immediatly.
this.attachMovie("Ball", "ball_mc", this.getNextHighestDepth(), {width:100, 
height:100});

There have been some interesting discussions about getter/setters here in the 
past that you can find in the archives.
Most of those go back to the AS1 days when we still had to use 
Object.addProperty()
(which AS2 still results to behind the scenes).

http://muzakdeezign.com/flashcoders/?q=getter%20setter
http://muzakdeezign.com/flashcoders/?q=implicit%20getter%20setter

regards,
Muzak

----- Original Message ----- 
From: "Holth, Daniel C." <[EMAIL PROTECTED]>
To: <Flashcoders@chattyfig.figleaf.com>
Sent: Tuesday, February 13, 2007 9:31 PM
Subject: [Flashcoders] Coding Standards: Use of Get/Set



I was wondering what people's thoughts were on the use of "get" and
"set" functions.  I personally have felt that creating functions such
as:

public function get theLetterA(){
return "a";
}

so the user can simply call someObject.theLetterA are confusing because
the user doesn't know if they are doing a function call or accessing a
public variable.  I prefer writing functions such as:

public function getTheLetterA(){
return "a";
}

So the user needs to explicitly call the function
someObject.getTheLetterA().

Are there advantages to using "get" and "set" that I'm not seeing?

I ask because I was always use getVariable() functions and started
reading ActionScript 3 with Design Patterns and the authors (as well as
many others I've read) are using "get" and "set" functions.

Daniel Holth
I.S. Programmer


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to