I have a very simple question regarding some software development solutions using the iOS SDK.
Suppose I have a class that controls the presentation of view objects in my application ( UIManager ). This class allows external controller classes to add view objects to it. Presentation objects can be of two types: subclasses CALayer and UIView .
My question is which interface is more suitable for such a UIManager class. For instance:
@interface UIManager : UIView {}
1) Is the id type too general?
2) Can having a different method signature for each type lead to terrible code duplication?
3) Is there a way to present the UIView and CALayer via <MyProtocolType> ?
Or, more commonly, having a class that handles these different objects interchangeably is not good?
The implementation of UIManager will be something like this:
@implementation UIManager // 1) - (void)addGenericViewObject:(id)genericViewObject { if ([genericViewObject isKindOfClass:[UIView class]]) { [_uiViewsContainer addSubview:(UIView*)genericViewObject]; } else if ([genericViewObject isKindOfClass:[CALayer class]]) { [_caLayersContainer addSublayer:(CALayer*)genericViewObject]; } } @end
Type checking is always bad, perhaps if <MyProtocolType> solves the situation, how can I represent both the UIView class and CALayer in the protocol? Both classes simply correspond to <NSObject> .
Thank you in advance
source share