WilliamKF
WilliamKF

Reputation: 43209

What does this C# declaration mean?

In a C# program, I see the following declarations:

public class myForm : Form
public abstract myForm1 : myForm
public interface myInterface
public interface myInterface2 : myInterface
public class myClass : myForm1, myInterface2

What does myClass mean to have myForm1 and myInterface2?

Is myForm1 the base class? If so, and there being no multiple inheritance in C#, what is this interface relationship to myClass? How does an interface differ from a class?

Upvotes: 0

Views: 299

Answers (2)

ukhardy
ukhardy

Reputation: 2104

Fowler says,

Inheritance and subclassing in OO languages is an implementation approach in which the subclass inherits the data and operations of the super class. It has a lot in common with subtyping, but there are important differences. Subclassing is only one way of implementing subtyping ... Subclassing can also be used without subtyping--but most authors rightly frown on this practice. Newer languages and standards increasingly try to emphasize the difference between interface-inheritance (subtyping) and implementation-inheritance (subclassing).

Two questions arise concerning the relationship between an object and a type. First, does an object have single type that can inherit from supertypes (single classification), or does it have several types (multiple classification)? Multiple classification is different than multiple inheritance. With multiple inheritance a type can have many supertypes, but each instance is of a single type that may have supertypes. Multiple classification allows multiple types for an object without defining a specific type for the purpose.

Upvotes: 2

BoltClock
BoltClock

Reputation: 724502

It means myClass derives from the myForm1 class, and implements the myInterface2 interface. No multiple inheritance takes place because you only extend one class.

In Java this would be expressed with two different operators, C# just conveniently uses the : operator for both:

class myClass extends myForm1 implements myInterface2

An interface is not a class; it's (to put it simply) a list of methods that an implementing type needs to have (or a list of rules to follow).

Upvotes: 7

Related Questions