objective c - Multiple instance variable types for class? -
is possible handle class different instance variable types? let's have class has 2 int instance variables, let's call them:
@interface classa: nsobject { int x; int y; } @end at same time want extend giving possibility handle different type on such instance variables so:
@interface classb: classa { double x; double y; } is possible?
i'm pretty sure can't 2 reasons:
- you can't repeat instance variables (
int x, double x). - it's pretty sketchy inherit 1 class, want change type of instance variables.
if don't want make separate classes these use-cases, perhaps abstract superclass work. if more you're trying solve, i'd able bit more helpful in area.
what seems want parametric polymorphism, objective-c not support. cocoa classes, nsnumber family, use abstract superclass many concrete subclasses, presumably different instance variable layouts (like describe in question). then, logic divided appropriately between abstract , specific. cocoa's class cluster design pattern, sort of weakened, ad-hoc answer parametric polymorphism of languages c++ , haskell.
Comments
Post a Comment