Inheritance question

fkheng

Well-known member
Joined
May 8, 2003
Messages
155
Location
Malaysia
When I create a form in vb.net, vb automatically makes use of

Inherits System.Windows.Forms.Form

With this, I am unabvle to inherit other classes as it is already taken up by this. Is this necessary? Is there another way aroun this problem?
 
If it doesnt inherit from form than the class will not be a form. You cant inherit from anything else if you want to have a form. Create another class and inherit from whatever you need.
 
i see, haih...then the purpose of inheritance in vb.net plays a very little role am i right? coz many things in vb are done thru the interface...

so my code on a form cant inherit a class? haih...
really no other way? if not ill have to define the functions in a module...and call the functions that way, would that be better? in fact, is that similar to inheritance?
 
Inheritance in .NET plays a huge role :) For example every control inherits from the base Control class.
If you put functions in a module you will not be able to inherit at all. If you want to inherit from something create another class. What are you trying to do? It will be easier to explain and get to what you need if I know what you are trying to do :)
 
hm.......
i mainly have many lines of code which are kind of similar, especially when i have many buttons on my form which, when clicked, connect to the database to carry out some operations...

i plan to centralise these lines of code, so that they can all be reused...

any ideas?
 
You dont need inheritance for that, you just need some functions to accept parameters that you need. Those should easily be implemented in your form class. Database connections dont require any special inheritance.
 
i see, er........would it be less efficient to create a few more database connections than to just maintain and reuse a single connection variable?
 
.NET does not support multiple inheritance. Thats what you are experiencing.

Still you could could have a new class that inherits from system...form and implement some general methods in that "root" form, then let your other forms inherit from the root form.

Even better, split your application in 3 or more layers (tiers). One for the GUI handling and nothing more. One for the Data Access (and nothing more) and one for business rules. In the business rules layers, you need not inherit from system..form.

So.
:-)
 
Back
Top