C# Inheritance and Interfaces

  • Thread starter Flavian Musyoka Mwasi
  • Start date

F

Flavian Musyoka Mwasi

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);
}


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?

I was wondering., wouldn't it be better to use the more
clearer VB-style or Java-style methods of invoking
inheritance and interface? After all this is not the era
of the criptic C++ style way of programming. I think this
would remove the confusion a great deal.

e.g.

interface ItextBox implements Icontrol {}

AND
public class EditBox inherits Icontrol {}


etc.


Flavian Musyoka Mwasi
Nairobi, Kenya
 
Ad

Advertisements

J

Jon Skeet [C# MVP]

Flavian Musyoka Mwasi said:
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.
 
Ad

Advertisements

M

Mohamoss

Hi Flavian
there should be no problem with that . In fact it is redundant to say
inherit or implements. If it is an interface then implement if it is class
then inherit. So you don't have to repeat these words since you know your
are referring to class or interface. Also there is the naming convention
that is supposed to make things even more clear; use only the capital I as
a prefix for interface name . I think all these factors more clearly rather
than cryptic.
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top