开发者

Is it possible to share code betwee classes that does not have the same parent?

I have two classes that are already subclasses of a different parent (due to an external library I cannot change this). However I want to share som开发者_StackOverflow社区e common code between them, say for example, code that handles an action after a popup dialog etc. How do I do this?


Refactor the shared code into its own class, and include an instance of that class as a field/property within your other two classes.


You can re-factor the appropriate code into a utilities class, and then have the two classes call it. As for the iPhoneSDK, you can probably have the utility method be the delegate method itself.


You could write a category on a common ancestor class. Then both classes could import that Category and call the common code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜