Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why Use Interfaces
Message
 
To
10/01/2008 02:32:10
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01278205
Message ID:
01281037
Views:
17
>>Unfortunately the debate you were so much up to was not about interfaces, but about using them to simulate MI. I am actually very interested in what you know about:
>>- What part of MI bad stuff is avoided by simulation? (as opposed to true MI)
>>- Why was true MI left out of the C# compiler?
>>Thanks.

>
>True MI was left out of the C# compiler because it probably didn't make much sense to Anders to put it in. And, since he invented C#, he can do anything he wants to with the language! <g>
>

And it didn't make sense for Anders because...? I find it hard to believe you don't know why, but just in case, here is a link (I know you won't take it from me) http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85562.aspx

>Seriously though, the problem with true MI (the bad stuff) can be shown by an example. First, let's start off with your example:
>
>
>  EveryThings          	    EatMe(theObjThatEatsMe)
>    |- LivingThings         FeedMe(theObjFed), WaterMe(theObjWatered)
>    |    |- Person
>    |    |- Cow
>    |    |- Nightshade
>    |- NonLivingThings
>         | - Cake
>
>
>So,from this starting point, let's create a few classes:
>
>
>public class LivingThings
>{
>    public virtual void FeedMe(theObjFed)  { }
>}
>public class CircusAnimals : LivingThings
>{
>    public virtual void PerformTricks()  { }
>    public virtual void TalkToMe() { }
>}
>public class FarmAnimals : LivingThings
>{
>    public virtual void EatMe(theObjThatEatsMe) { }
>    public virtual void TalkToMe() { }
>}
>public class TrickGoats : CircusAnimals, FarmAnimals
>{
>}
>
>
>OK, so it doesn't follow your example hardly at all. Oh well. <g>
>
>Now, here's the problem ... in the TrickGoats class, which TalkToMe() method would need to be executed? CircusAnimals are probably talked to (by their trainers) a lot differently than FarmAnimals are talked to (by the farmer). I suppose we could have an overridden TalkToMe() method in the TrickGoats class, but what if you didn't do that? You see how this could easily get complicated.
>
>Now, if we solved this by simulating MI with Interfaces, we'd *have* to implement the method in the TrickGoats class and thus there would be no ambiguity:
>
>
>public interface ICircus
>{
>    void PerformTricks();
>    void TalkToMe();
>}
>public interface IFarm
>{
>    void EatMe(theObjThatEatsMe);
>    void TalkToMe();
>}
>public class TrickGoats : LivingThings, ICircus, IFarm
>{
>    public void PerformTricks() { }
>    public void EatMe() { }
>    public void TalkToMe() { }
>}
>
>
>So, this probably isn't the greatest example, but it's too late for me to be thinking all that clearly and it was the best I could come up with. Still, I think it probably illustrates the answer to your questions.
>
>~~Bonnie

So all the bad stuff avoided by simulating MI is... one: the compiler will not compile if you forget to write implementation code.
That may be a big deal, but is it has zero to do with why MI (simulated or not) is, in most cases not required or not appropriate.
I appreciate you stayed so late to answer, and I appreciate the humor.
Thanks.
Doru
Previous
Reply
Map
View

Click here to load this message in the networking platform