dot syntax vs method syntax with getter=

后端 未结 4 413
清酒与你
清酒与你 2020-12-18 23:30

I\'m not sure how much use this question is but it seems interesting to me...

I thought that using property/synthesize statements was equivalent to me creating the ge

4条回答
  •  -上瘾入骨i
    2020-12-19 00:01

    Well concerning dot notation, let me cite Aaron Hillegass (Cocoa Programming for Mac OSX, 3rd. Ed):

    "Overall, I think that this is a rather silly addition to the language since we already had a syntax for sending messages."

    When you have a member variable on, and your getter for this variable is called isOn then .on and .isOn are two very different kind of things. By using the getter (and probably a setter, too) you will adhere to the "information hiding" promise, whereas by using direct access to the member variables you won't. Cocoa won't enforce those things as it is relying on conventions. It's up to you to decide which way is right for you. Considering convention, you would have to stick to setters and getters - no matter what names you give them, though.

提交回复
热议问题