开发者

Select baseclass type at runtime like templates

I have a component which is used as the base class for a lot of more complex components.

Currently this base inherits from UIScrollView.

What I want now, is to have an alternative base view with 99% of the same functionality, but which will inherit from UIView. In C++ I would most probably have done this with templates, but how can this be done in Objective-C?

Example:

                |-- ComplexDerivedClass_1
                |
BaseClass  -----|-- ComplexDerivedClass_2    |-- EvenMoreComplexDerived_1
                |                            |
                |-- ComplexDerivedClass_3 ---|-- EvenMoreComplexDerived_2 
                                          开发者_如何学JAVA   |
                                             |-- EvenMoreComplexDerived_3

My aim is that BaseClass may inherit either from UIView or from UIScrollView and that this will be decided at runtime (without creating special implementations of each derived class for either UIView type base or UIScrollView type base).

One solution is of course to have the base class inherit from UIView, and if required, add another UIScrollView to it at runtime, but I am wondering whether it can be done without this.


Have you looked at protocols? I'm not that good with c++, but I think that's the closest thing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜