On Oct 18, 4:02 pm, Janos <jkazs...@intARTS.comwrote:
then how do you solve in C# cases like (I do not draw the inheritence
lines, I hope it is obvious):
Class Vehicle with static constant: NumberOfWheels
Class Auto: NumberOfWheels = 4; Class Bycicle: NumberOfWheels = 2;
Class Amphibian: NumberOfWheels =0;
There should be only one NumberOfWheels in each class (because it is
common for all instances), but they should have different values.
The number of wheels should be related to an *instance*, with Vehicle
having a protected constructor taking the number of wheels. Auto would
always pass 4, Bicycle would always pass 2 etc.
It has to be instance data otherwise you can't ask an arbitrary
vehicle how many wheels it has.
An alternative if there are many similar values is to have flyweight
"VehicleKind" with Auto, Bicycle etc instead of using polymorphism -
each vehicle would have a VehicleKind which in turn would know how
many wheels it had etc.
Jon