An OOP-style qustion
in
Programming Questions
•
2 years ago
-all class names in this example are fictious-
static int type = 0;
statement which represents it's type for switches in my program. Accordingly I have initiated similar things in all the other classes like
static int type = 1; //for LowObject
static int type = 2; //for HighObject
and so on...
Then when I get an Object, passed as a function parameter, I want my switch to know which type of object is it actually. Objects of class Object never meets in the program, it is merely a reference template. But then, in the switch(passedObject.type) statement, it always says that passedObject.type = 0!!! Actually this seems quite logical to me now.. but still I have this question: how can I effectively determine, which one of the extended classes does the passed object belong to?
If possible, I would not like to use reflection. Is there any memory and time cheap approach for such an issue?
1