By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,670 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,670 IT Pros & Developers. It's quick & easy.

Multiple inheritance

P: n/a
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?
Nov 15 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
C# does not support multiple inheritance.

You could make Base an interface and implement that interface.
HTH
Brian W

"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:es****************@TK2MSFTNGP12.phx.gbl...
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?

Nov 15 '05 #2

P: n/a
On Fri, 6 Feb 2004 14:11:39 -0500, Chuck Bowling wrote:
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
--
Tim Smelser - MVP Visual C#
To email me, make the snot hot.
Nov 15 '05 #3

P: n/a
Chuck Bowling wrote:
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?

Or you might try...

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

class myClass : Base
{
...
}
Nov 15 '05 #4

P: n/a
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.

=====

"Marcus Ahlberg" <ca*********@swipnet.se> wrote in message
news:OR**************@TK2MSFTNGP10.phx.gbl...
Or you might try...

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

class myClass : Base
{
...
} Chuck Bowling wrote:
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?

Nov 15 '05 #5

P: n/a
"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
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.
Nov 15 '05 #6

P: n/a
Chuck,
Depending on what Base is doing, consider creating an Extender Provider
instead.

http://msdn.microsoft.com/library/de...erprovider.asp

An Extender Provider is a component that you can place on a form that adds
properties to other components & controls on the form.

Hope this helps
Jay

"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
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.

=====

"Marcus Ahlberg" <ca*********@swipnet.se> wrote in message
news:OR**************@TK2MSFTNGP10.phx.gbl...
Or you might try...

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

class myClass : Base
{
...
}

Chuck Bowling wrote:
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?


Nov 15 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.