Multiple inheritance

  • Thread starter Thread starter Chuck Bowling
  • Start date Start date
C

Chuck Bowling

C# newbie warning...

It'll probably be easier to explain what i want in code:

-------

abstract class Base
{
...
}

class myClass : Base, System.Windows.Forms.TextBox
{
....
}

class myClassContainer
{
Base myBaseClass;
}
 
C# does not support multiple inheritance.

You could make Base an interface and implement that interface.


HTH
Brian W
 
C# newbie warning...
It'll probably be easier to explain what i want in code:

abstract class Base
{
...
}
class myClass : Base, System.Windows.Forms.TextBox
{
...
}
class myClassContainer
{
Base myBaseClass;
}

I know that multiple inheritance isn't possible so how do i implement an
architecture like this?

You can't have implementation inheritance, so you would need to re-code
everything that would normally be in the Base class in the myClass class
and have Base become IBase - an interface.

interface IBase
{
...
}

class myClass : System.Windows.Forms.TextBox, IBase
{
...
}

class myClassContainer
{
IBase myBaseClass;
}

Tim
 
Chuck said:
C# newbie warning...

It'll probably be easier to explain what i want in code:

-------

abstract class Base
{
...
}

class myClass : Base, System.Windows.Forms.TextBox
{
...
}

class myClassContainer
{
Base myBaseClass;
}
Or you might try...

abstract class Base : System.Windows.Forms.TextBox
{
...
}

class myClass : Base
{
...
}
 
Thanks, but the problem with that is that it doesn't provide the
functionality that I want. I need a base set of attributes and methods that
I can use as a template for other classes and as a foundation object for the
collection class. If i do as you suggest then I'll have to create a
different class for every new version of my class which kind of defeats the
purpose of having an abstract class in the first place.

What I want is something like:

abstract class Base{}

class BaseTxt : Base, System.Windows.Forms.TextBox{}

class BaseTree : Base, System.Windows.Forms.TreeView{}

class BaseGrid : Base, System.Windows.Forms.GridView{}

class myClassContainer
{
Base myBaseTree;
Base myBaseTxt;
Base myBaseGrid;
}

I don't want to have to use individual type declarations for each type
derived from Base.

=====
 
Thanks, but the problem with that is that it doesn't provide the
functionality that I want. I need a base set of attributes and methods that
I can use as a template for other classes and as a foundation object for the
collection class.

You simply want aggrigation, not inheritance. If you just define your
MyBaseAttributes class you can declare a member of that type in any other
class in which you need it along with a single property that publishes the
MyBaseAttributes member to the clients of your class.

Martin.
 
Back
Top