# Class, setter and getter

**URL:** <https://forum.kirupa.com/t/class-setter-and-getter/57266>\
**Category:** Uncategorized\
**Created:** [July 11, 2004, 11:45pm UTC](https://forum.kirupa.com/t/class-setter-and-getter/57266 "2004-07-11T23:45:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Chen](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@Michael\_Chen](https://forum.kirupa.com/u/Michael_Chen)\
**Post date:** [July 11, 2004, 11:45pm UTC](https://forum.kirupa.com/t/class-setter-and-getter/57266/1 "2004-07-11T23:45:36Z")

</div>

Hi Everyone 🙂

Does anyone use this kind of syntax for creating the setter and getter for their custom classes?

public function get foo():dataType {  
return \_foo;  
}  
public function set foo(value:dataType):Void {

}

Does the above syntax have any advantages over the bottom one?  
I find the top one quite confusing (esp. with the extra space).

public function getFoo():dataType {  
return \_foo;  
}  
public function setFoo(value:dataType):Void {

}

Thanks in advance :sure:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2004, 12:53am UTC](https://forum.kirupa.com/t/class-setter-and-getter/57266/2 "2004-07-12T00:53:02Z")

</div>

I believe the top one (with the space) is implicit.  
That means you can reference class variables without actually calling the function.

so like, rather than:

person1.setName(“Bob”);

you can do this:

person1.name = “Bob”;

Personally I don’t like it, but I could see uses for it.

Hope this helps. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2004, 1:01am UTC](https://forum.kirupa.com/t/class-setter-and-getter/57266/3 "2004-07-12T01:01:59Z")

</div>

Thanks, I get it now 🙂
