Re: C# Inheritance and Interfaces

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 05/31/04


Date: Mon, 31 May 2004 09:20:02 +0100

Flavian Musyoka Mwasi <musyoka7@hotmail.com> wrote:
> I'm a novice programmer just beginning to learn the new C#
> language.
>
> I'm a bit confused about the way Inheritance and
> Interfaces are constructed in C#. The following examples
> may help clarify my confusion:
>
> interface IControl
> {
> void Paint();
>
> }
>
> interface ITextBox: IControl
> {
> void SetText(string text);
> }
>
> public class IControl
> {
> void SetText(string text);
> }

Hang on - you've now got two types called IControl - one an interface,
one a class. That's a really bad idea. Was it what you intended.

> public class EditBox : IControl
> {
> public void Paint() {...}
> public void Bind(Binder b) {...}
> }
>
> Can the designers of the language ponder over this and
> maybe think of a way to remove this confusion in future
> releases of the language?

What confusion?

> I was wondering., wouldn't it be better to use the more
> clearer VB-style or Java-style methods of invoking
> inheritance and interface?

Interfaces in C# are very similar to interfaces in Java.

I'm still missing what your actual problem with how interfaces work in
C# is.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: High performance alternative to MI of virtual bases
    ... > implementations of interfaces. ... Heavy use of MI is abuse for the same reasons that simple inheritance is ... Inheritance -- multiple or otherwise -- is meant ... use of the core standard C++ language... ...
    (comp.lang.cpp)
  • Re: Static vs Dynamic
    ... > When you use reflection like this, it tells me that the base language ... Reflection as a base API distinguishes Java from its C++ ... interfaces are great for stabalizing types if you need to. ... Dog dog = new Dog; ...
    (comp.lang.lisp)
  • Re: Interfaces.
    ... modern language because they provide a way of separating the ... First of all, being a newbie, let me welcome you to python. ... Pythons dealings with interfaces are no exception. ... Java code that has successfully passed all the compile-time semantic ...
    (comp.lang.python)
  • Re: Name that language (if it exists), or comment on ideas for language.
    ... No implementation inheritance, only interfaces and delegation (with ... Language level support for resource scoping. ...
    (comp.object)
  • Re: No Equals on interfaces
    ... > for interfaces which is definitely not true and thus misleading. ... >> that's just language partisanship, it makes me think that the designers ... > reference to an object or a null reference, ... I don't think someVar is an ISomeInterface, ...
    (microsoft.public.dotnet.languages.vb)