Quote:Original post by antareus
No inheritance is taking place with static methods. The base class's implementation may be obscured by a subclass implementation, but that isn't the same thing as inheritance. If you're interested in knowing the type of the derived class, add a Type argument to the static method's argument list. Classes (be they base or derived) can simply pass in this.GetType() (or obj.GetType()) for that argument.
I have a class. it has a static method. I subclass my class. my subclass has the static method. how is that not inheritance?
Quote:
As Arild Fines said, it makes absolutely no sense.
A static method is has only one "instance" in memory; every time you call it, it's that same code that is called. It receives no this pointer. How can you expect it to return different results depending on who calls it?
Tell us what you intend to do with it and we might provide you with a better solution.
A concrete example:
Okay. I have a class called 'View'. it gives me lots of functionality for searching on my objects and my UI knows how to display (and therefore subclasses of it). (in an ideal world this class would be abstract, however in order to use Designer in VS it can't be abstract - using VS & its Designer is out of my control)
I also have a car class and a driver class.
I then make 2 subclasses of View, one called 'carView' and another called 'driverView'.
now I know there is a link between carView and car and between driverView and driver. I would have naturally wanted to express this with a static method or property on the View , something like: public static Type targetObjectType. logically, the target-object-type is defined at the class-level. its shared across all objects of the same class.
When my window manager (or whatever) gets hold of my carView, all it sees it as is a View. I do not want it to specifically know about any one of my subClassed view-s.
I also don't want car - my data object - to know about carView.
I'm now given a car object, I want to be able to find a view to represent it. I would do this by reflecting on my assembly, trotting over the different Types in my assembly at run-time and making an index relating an object-type to a view type so I could look it up. I don't want to instantiate every search screen in my assembly to build this index.
does this make it more clear?