objective c - Property with redefined accessor still accessible -


i wondering usefulness of redefining getter of property. documentation states can redefine getter of property using getter:

@property (getter=isfinished) bool finished; 

from understand, callers should use:

myobj *obj = ...; obj.isfinished; 

but nothing prevents do:

myobj *obj = ...; obj.finished; 

since property can still freely accessed, what's point of redefining getter?

wouldn't more concise , readable do:

@property bool isfinished; 

by @property (getter=isfinished) bool finished; declare explicit getter, implicit setter, and implicit ivar. (in former versions of objc, have needed `@synthesize in addition). however, there no need getter/setter use automatic ivar, not ivar @ all. thus, can have private ivar, or set number of ivars, or other 'magic'.

the dot syntax syntactic sugar avoid [].

edit till here, answered question "what's point of redefining getter?".

to answer name/privacy part: if want bool, first alternative fine. if want protected/private ivar, declare ivar in way, , write own getter/setter.

to name property isfinished considered not (unless read property), since original setting (not dot semantic) setisfinished:val (instead of setfinished:val), considered not easy readable. however, have getter isfinished allows if ([obj isfinished]) ... or if (obj.isfinished) ... considered quite readable.

thus, naming , privacy independent concepts.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -