# Getter/Setters or Public Methods?

**URL:** <https://forum.kirupa.com/t/getter-setters-or-public-methods/263520>\
**Category:** flash\
**Created:** [June 16, 2008, 8:31pm UTC](https://forum.kirupa.com/t/getter-setters-or-public-methods/263520 "2008-06-16T20:31:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dail](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@dail](https://forum.kirupa.com/u/dail)\
**Post date:** [June 16, 2008, 8:31pm UTC](https://forum.kirupa.com/t/getter-setters-or-public-methods/263520/1 "2008-06-16T20:31:27Z")

</div>

When you all write your classes, and you want to expose certain elements of your class to outside parties etc. Do you generally use getter/setters or public functions?

To me a getter/setter is for adjusting a property of your class where as a method is more for say adjusting its behaviour state. For instance, a method called classInstance.play() that plays a video file makes more sense than say a setter classInstance.play = true.

But then, in some cases the distinction is less defined. For instance, changing the volume of something, volume is a property, and seems to fit with a getter/setter pair well: classInstance.volume = .1 as opposed to classInstance.volume(.1).

I guess its a matter of style, but are there any ‘hard and fast’ rules about when to use a getter/setter verses when to use a public method?

(I realise that getters/setters are also public)

---

<div class="post-metadata">

**Author:** ![wvxvw](https://avatars.discourse-cdn.com/v4/letter/w/a9a28c/32.png) [@wvxvw](https://forum.kirupa.com/u/wvxvw)\
**Post date:** [June 16, 2008, 10:05pm UTC](https://forum.kirupa.com/t/getter-setters-or-public-methods/263520/2 "2008-06-16T22:05:01Z")

</div>

It’s not like AS2, so, whenever I can, I try to use public variables - less code to write =) Meaning, I use get/set only in these cases: I need only get, without set; I need to make some calculation before assigning final value (like rounding it or, making calculations more precise / avoid irrational values, like setting bitmap size to \< 1 || \> 2280 etc; or if I need some sort of notification, when property is reset.
