oop - Private classes in Objective C -
i pattern nested private class in objective c.
requirements are:
class not visible/accessible other classes.- class can execute methods (i.e., not c struct)
- containing class members visible/accessible nested class
considering comments, simplifying requirements:
- inner class may accessible other classes, not visible (similar using category hide private methods).
- inner class not have nested
is still not possible?
objective-c has no notion of private classes or private instance variables in formal declarative fashion.
instead, visibility in objective-c entirely controlled declare something. if in header file, can imported else. if declared in implementation file, cannot (reasonably) imported and, therefore, private compilation unit.
and "it", mean pretty can declared; class, global, etc...
i.e. if stick @interface/@implementation
pair class in .m
file, class private compilation unit. of course, without namespaces, make sure class uniquely named.
consider this:
foo.h:
@interface foo: nsobject ... public interface @end
foo.m:
@interface __foosupportclass: nsobject ... interface here ... @end @implementation __foosupportclass @end @interface foo() @property(retain) __foosupportclass *__foosupport; @end @implementation foo @synthesize __foosupport = foosupport__; ... etc ... @end
that gives private-by-visibility support class available in implementation instance variable , setter/getter methods on class not visible outside compilation unit either.
(note objective-c has "instance variables", not "member variables". similar, you'll better off using vocabulary of language.)
Comments
Post a Comment