Say inherited from a class, I can invoke [self someMethod] if someMethod is rewritten; I can also invoke [super someMethod].

What if I use composition instead. Say I have porperty

@propery (nonatomic, strong) XXXController xxController;

Use [self.xxController someMethod] to invoke someMethod, but how to invoke xxController's super version someMethod?

有帮助吗?

解决方案

No, you can't do this*. Using composition does not allow you to break encapsulation.

*(It is actually possible to do this using runtime functions but you really, really, really shouldn't do that!)

其他提示

You can't do that. And you don't want to. Composition styles or not, an object should implement it's own methods, and call it's own super if necessary.

Instead, you should subclass XXXController to work how you want, calling super as necessary in that subclass.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top