Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ace2600

macrumors member
Original poster
Mar 16, 2008
71
0
Austin, Texas
I'm in the process of standardizing the code for my iPhone apps. One issue I'm debating on is when to use accessor methods for private class variables only used by that class. For public access to member variables, I do use getters and setters (usually via properties), but for member variables I don't want exposed outside of the class, I'm not as sure.

I feel there's definitely an advantage to using "private" setters, because they take care of releasing the old value too. I'm not so sure about getters, because most of the time, the getter will just return the member variable. I will be making these "private" accessor methods hidden using categories.

What are your thoughts? Do you always use "private" accessor methods for non-exposed member variables? Or do you always reference the variable directly in the class? Or maybe always use a setter but always reference the variable directly for gets?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.