1 Replies - 199 Views - Last Post: 22 April 2013 - 06:19 PM Rate Topic: -----

#1 lifeinbinary  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 158
  • Joined: 15-February 11

Modifying properties directly vs. using getters (obj-c)

Posted 22 April 2013 - 12:31 PM

I always hear that you should always use getters to modify properties. But in casses where I just want to add 1 to an int do I really need to use the getter... it just seems like overkill. What's the reasoning behind using getters ans setters? Ex:

Using setter:
[self.state setTotalBasesToAllocate:self.state.totalBasesToAllocate + 1];



Without setter:
self.state.totalBasesToAllocate++;



Because I see you cant modify like this:
[self.state totalBasesToAllocate]++;



This tries to modify a side-effect or something like that. I took a bad habit to modify class vars directly in Java by naming them public... my teachers always bitched about it but could never give me a reason why this was bad. So what's the real deal on this subject?

Sam

This post has been edited by lifeinbinary: 22 April 2013 - 12:32 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Modifying properties directly vs. using getters (obj-c)

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Modifying properties directly vs. using getters (obj-c)

Posted 22 April 2013 - 06:19 PM

If you understand data encapsulation you might see it better. Have a google.

Getters get values and setters set values, btw.

This post has been edited by ButchDean: 22 April 2013 - 06:20 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1