tags:

views:

18

answers:

1

In Objective-C 2.0, I usually make an assign property for ivars that are primitive types like float. Then it occurred to me that I can access them from outside the class with obj->variable notation. I imagine that this is bad practice: is it?

+2  A: 

Yes, it's bad practice because it breaks encapsulation of your class' implementation details. The @property declaration is a public API statement ("my class provides a property of type, e.g. float), not an implementation statement ("my class has a float instance variable"). Clients of your class' API should not know its implementation details lest you be prevented from changing those details without breaking client code.

Barry Wark