|
This is where I absolutely hate generic interfaces: I wish there was a way to be able to mark the return value (or anything else, for that matter) as the type that implements the interface. You know - something that can be done with simple C++ templates quite easily.
For instance, ICloneable.Clone would be like this:
public interface ICloneable
{
impl_type Clone();
}
so that any object that claimed to implement ICloneable would have to have a Clone() method that returned an object of that type, not a Clone() that returned an Object.
The important point on common bases is to ensure substitutability - that's the (real) sense of inheritance! But substitutability gets lost if you do it your way. Two different instantiations of a template are not type compatible. Consider you want to clone a collection of objects for which you don't know the exact types, what would you do?
However, I also hate
these annoying casts. The best solution would be to support two Clone() members - one returning the real class type and one returning the common base.
--
Daniel Lohmann
http://www.losoft.de
|
|
|
|