Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Interface with base class
Message
Information générale
Forum:
ASP.NET
Catégorie:
Programmation orienté objet
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01416072
Message ID:
01416621
Vues:
60
Hi Viv,

> I don't see why not - AFAICS no strong-typing rules are being broken.

But they are...
Test x = new Test();
ITest y = (ITest) x;
x.Parent.MethodOfDerivedClass();
y.Parent.MethodOfDerivedClass();
The first method call of MethodOfDerivedClass() would need to work since x.Parent is defined as being of type DerivedClass. The second method call would fail, though, because the interface returns the base class. In both cases, however, the code calls exactly the same Parent getter because the interface is implemented implicitly. So, you have the same method but two signatures. If that doesn't violate strong typing, I don't know what else would... The compiler can't do an implicit cast here.
--
Christof
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform