rbulph said:
If you want to have a class inherit from more than one other class you get a message from VB that only one Inherits statement is allowed in each class. But why? Suppose I have a Securities class and a Debt Class. A Loan Class would inherit Debt. A Shares Class would inherit Securities. A Bonds Class would inherit Debt and Securities. It seems a reasonable enough thing to want to do to me. I guess you have to be sure there's no conflict between properties in the Securities and the Debt class, but I'm sure that could be dealt with.
Is there any decent workaround to this?
Best workaround I can see is to create an Interface for each class you want to inherit including all the public properties, events, methods & functions you need exposed.
create an instance of the classes you need to your current class to have and expose those methods/properties/events/functions that you want/need to expose.
It's more work than just inheriting from the class, but it's less work than rewriting the .net framework to allow multiple inheritance.
Personally, in most cases I'd prefer it this way. I like to see exactly what I'm using and have accessable and sometimes inheritence hides that from me.
If you plan on reusing these "base classes" (ie, you wanted multiple classes to inherit from them), do this in a "Code Snippit" and store it in the IDE (and back it up!). you can lay down the code of you exposing all the methods/properties/events/functions with a few mouseclicks/keystrokes.
An interface isn't nessicary, technically, but if you want all the classes that inherit from your "base classes" to all expose the same methods, only interfaces will enforce that if you change it, that you expose the new methods and the IDE will show you that with code errors until you add what you need to add.
Ideal? Maybe not, but it seems to get the job done and if you're using "Snippits", then most of your work is up front, barring changes in the classes at a later point.