objective c - How to overwrite parent properties (redeclaration of parent property as a static variable)? -
it possible have type in parent class subclass overwrites?
the idea here have shape class, subclasses of rectangles, square, circles, etc. wondering if it's possible overwrite definition of 'shapetype' int property in parent class. this?
e.g. in globals.h
#define kshapetype_rectangle = 1 #define kshapetype_square = 2 #define kshapetype_triskaidecagon = 13 // try pronouncing this!
in shape.h
@interface shape : nsobject @property int shapetype; @property int shapeid; @property uicolor shapecolor; @end ....
in rectangle.h
#import globals.h @interface rectangle : shape @property static (nonatomic, readonly) int shapetype = kshapetype_rectangle; // how working? @end
so 2 questions:
1) such thing possible - i.e. redeclaration of parent property static variable
2) yes or no (1), best coding style sort of thing? i'm not experienced in obj-c patterns, if 1 exists, suggest source me @ please?
thanks lot!
there no concept of objective-c property being static variable. objective-c property syntax shorthand declaring 2 methods, getter , setter (or getter in case of readonly
properties). can override either or both of methods in subclass , have them , set value from/to static variable/value in subclass if want. there's nothing preventing that.
in case this:
- (int)shapetype { return kshapetype_rectangle; }
not philosophical, having such property seem creating redundancy type system. put differently, why have property have override in every subclass? in case why have shapetype
return kshapetype_rectangle
when know instance rectangle virtue of being of rectangle class?
Comments
Post a Comment