I can't seem to figure this one out.
I've got a bunch of classes (lets say, RedBox, BlueBox and GreenBox) which all implemtn IBox. This works perfectly. However, I now have a requirement that each box implements a particular static method, so I can get a non-instance-specific bit of data out. Lets call it GetVersion().
Whilst I can create a GetVersion method in IBox and ensure that each Box implements it as an instance method, that means that to call GetVersion, I need to instantiate an object of the class, and then call it. This seems a bit of a waste, given that what I want from the class is specific to the class, and not any particular instance of the class.
Is there a way of enforcing the existence of a static GetVersion() on everything that implements IBox? I thought about creating an abstract Box class and using inheritance, but you can't mark a static method as being virtual and force it to be overridden.
Any ideas?
I've got a bunch of classes (lets say, RedBox, BlueBox and GreenBox) which all implemtn IBox. This works perfectly. However, I now have a requirement that each box implements a particular static method, so I can get a non-instance-specific bit of data out. Lets call it GetVersion().
Whilst I can create a GetVersion method in IBox and ensure that each Box implements it as an instance method, that means that to call GetVersion, I need to instantiate an object of the class, and then call it. This seems a bit of a waste, given that what I want from the class is specific to the class, and not any particular instance of the class.
Is there a way of enforcing the existence of a static GetVersion() on everything that implements IBox? I thought about creating an abstract Box class and using inheritance, but you can't mark a static method as being virtual and force it to be overridden.
Any ideas?