Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interface with base class
Message
From
05/08/2009 04:25:02
 
 
To
04/08/2009 23:52:27
General information
Forum:
ASP.NET
Category:
Object Oriented Programming
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01416072
Message ID:
01416159
Views:
57
Hi Bonnie,

I knew that the compiler would make an implicit cast in this case - just thought it would make the same implicit cast for the interfaces example. I don't see why not - AFAICS no strong-typing rules are being broken. If the compiler accepts that DerivedClass 'is a' BaseClass in one case why not in the other?

IAC, in the real case I don't think this option is open to me. I'm working with the EntityFramework and 'Parent' is acutally an instance of a class derived from EntityObject so the Interface I'd need is:
public interface ITest
 {
      EntityObject Parent { get; }
 }
Oh well, best,
Viv


>I think you want this (and it should work fine):
>
>
>    public class Test : ITest
>    {
>        public BaseClass Parent
>        {
>            get {return new DerivedClass(); }
>        }
>    }
>
>
>~~Bonnie
>
>
>>I thought I'd used this sort of construct before. But the compiler insists that the type of Parent in Test must be BaseClass.
public interface ITest
>>    {
>>        BaseClass Parent { get; }
>>    }
>>
>>    public class BaseClass {}
>>
>>    public class DerivedClass : BaseClass{}
>>
>>    public class Test : ITest
>>    {
>>        public DerivedClass Parent
>>        {
>>            get {return new DerivedClass(); }
>>        }
>>    }
Am I cracking up?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform