How good is it to use extern in Objective C?
It does make coding for some parts easy.. but doesn’t it spoil the object orientation?
How good is it to use extern in Objective C? It does make coding
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ll find that
externis used extensively in the Cocoa frameworks, and one would be hard-pressed to find a convincing argument that their OO is “spoiled”. On the contrary, Cocoa is well-encapsulated and only exposes what it must, often via extern. Globally-defined constants are certainly the most common usage, but not necessarily the only valid use.IMO, using
externdoesn’t necessarily “spoil” object orientation. Even in OO, it is frequent to use variables that are accessible from anywhere. Usingexternis the most frequent workaround for the lack of “class variables” (like those declared withstaticin Java) in Objective-C. It allows you to expand the scope in which you can reference a symbol beyond the compilation unit where it is declared, essentially by promising that it will be defined somewhere by someone.You can also combine
externwith__attribute__((visibility("hidden")))to create a symbol that can be used outside its compilation unit, but not outside its linkage unit, so to speak. I’ve used this for custom library and framework code to properly encapsulate higher-level internal details.