[AS3] Discussion on getters/setters etc

Hi this is forked from this thread in order to avoid hijacking:

I just want to start by saying that I respect that people can get emotional about this and have strong opinions and I personally hope that I don’t offend anyone by stating mine. I am also always open to changing my opinion but I expect a very strong argument first! :slight_smile:

[QUOTE=Thinker2501;2529702]I’d like to respond to Shaedo’s comments regarding getter/setter methods. While you will find some programmers that do not like doing this, they are usually from a school of thought separate from OOP (object oriented programming) methodology.

Actionscript 3 is an OOP language in the purest sense of the word. When developing Flash applications you will make your life considerably easier to work with a strict OOP approach yourself. At the core of this methodology is the concept of compartmentalizing.

Using getter/setter methods maintains the consistency of this approach guaranteeing that only code within a class can read/write that class’s vars.

[/QUOTE]

@ Thinker2501 fair enough. I respect your opinion but I disagree on a few things:
“Actionscript 3 is an OOP language in the purest sense of the word.” Personally I would say no more so than say JAVA, it has elements like classes etc and lends itself very well to OOP but you can write it in a purely procedural fashion which I think people that code purely on the main time line predominantly do, and I would not be surprised if that is the majority of people that code in AS3 (designers etc). (although I have no especial knowledge of how the distribution of AS3 codes apply their techinques)

“you will make your life considerably easier to work with a strict OOP approach yourself.” yes and no, I personally would say to people learn and understand and where possible apply OOP when coding AS3 for flash but don’t be limited by it. If you do enough coding you will encounter situations where procedural coding makes more sense, in particular when you are not coding in objects.

“Using getter/setter methods maintains the consistency of this approach guaranteeing that only code within a class can read/write that class’s vars.” Sure I acknowledge that many top level programmers have this view but personally I think that if you have a function like a getter or a setter then really you are simply creating an alternate method of externally changing a var, in effect making it public whilst declaring it private.

That all said I do agree that your arguments make sense and I do agree that they are true and valid points. for example “At the core of this methodology is the concept of compartmentalizing” is I think quite true and applicable to this situation.

So personally I see getters and setters as a slower method of achieving the same result and will (probably) never use them as such.