Is this possible in VB.NET !??! inheritance..

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Imagine I have two classes A and B.

Class A has the function I, function J and Attribute K.

Class B has the funcion X, function Y, Attribute Z.

Is it possible to establish the following Class C through interitance:

Class C which has the attribute K inherited from Class A and the attribute Z
inherited from Class B ?

If this is not possible why not!??! In the real world example I was thinking
of maybe
An CustomerInvoice class , that interhited the attributes from a Customer
class, Product class and Order class, but necessarily all of the functions.
 
Sure. Have Class B inheirit from Class A then create a new class C that
inheirits B.
 
You cant do multiple inheritance in VB.NET. You can do what Dennis suggests,
or create interfaces for the multiple objects and implement all the
interfaces.

Rgds,
Anand M
VB.NET MVP
http://www.dotnetindia.com
 
What do you mean interfaces !!? omg I am lost.

Is there a reason why multiple inheritance is not supported !?!?!?
Do other OOP languages like Java support it !?
 
Bob,

There was a discussion some weeks ago about this, however you said a real
world example

In real live you can have a class humans
You can even inherit the class man from that
And you can inherit the class woman from that

But it is not logical to make a class humans again from man and womans.

A specific man can have special appierance (what he got maybe from his
mother, who got it maybe from her father), however that are in my opinion
not class properties as by instance 7 neck bones as is for most mammals.

Trying to do it in another way gives in my opinion bad design.

Just my thought,

Cor
 
Bob,
By "Multiple inheritance" do you mean "IS A" or "HAS A".

For example a Car has a Tire, however a Car is not a Tire.

Multiple inheritance normally refers to "IS A", however you Customer Invoice
example sounds like "HAS A". As the others have suggested .NET (VB.NET & C#)
along with Java do not support multiple inheritance except via Interface.

I would expect a CustomerInvoice would have a Customer, a Product, and an
Order.

However CustomerInvoice would not be a Customer, a Product, nor an Order.

Class C which has the attribute K inherited from Class A and the attribute
Z
inherited from Class B ?
Based on the CustomerInvoice example, I would expect:

Class C
Public Property A As A
Public Property B As B
End Class

Or with CustomerInvoice:

Class CustomerInvoice
Public Property Customer As Customer
Public Property Order As Order
Public Property Product As Product
End Class

Then within my code I could:

Dim invoice As CustomerInvoice
invoice.Customer.Name = "Jay"
invoice.Customer.Address = "Everywhere"

invoice.Order.Amount = $1

Hope this helps
Jay
 
Use the relatively cleaner and newer language from the devil. Use C #.
It has all that Vb.net offers as a language and multiple inheritance
also. Be warned that the design time envirionment [I was informed , i
have not even tried] for c# may make you cry for ..mummy!..
 
Mahesh said:
Use the relatively cleaner and newer language from the devil. Use C #.
It has all that Vb.net offers as a language and multiple inheritance
also. Be warned that the design time envirionment [I was informed , i
have not even tried] for c# may make you cry for ..mummy!..

I'm certain that I'm correct in saying that the .Net framework itself
doesn't offer multiple inheritance, which means that C# (just like VB.Net)
doesn't support multiple inheritance. The only thing you can do is implement
multiple interfaces or use multiple levels of single-inheritance objects, as
already described.
 
Question.. I'm really new at this so bear with me..

Couldn't you do this:

Public Class NewClass
Inherits A

Public Class FromB
Inherits B
End Class
End Class

And just have the properties for the attributes of B in the newclass and
in the functions for those properties just get and set in the FromB class???

Aaron
Mahesh said:
Use the relatively cleaner and newer language from the devil. Use C #.
It has all that Vb.net offers as a language and multiple inheritance
also. Be warned that the design time envirionment [I was informed , i
have not even tried] for c# may make you cry for ..mummy!..


I'm certain that I'm correct in saying that the .Net framework itself
doesn't offer multiple inheritance, which means that C# (just like VB.Net)
doesn't support multiple inheritance. The only thing you can do is implement
multiple interfaces or use multiple levels of single-inheritance objects, as
already described.
 
Mahesh,
C# does not have multiple inheritance of classes! Period.

C# does allow you to implement multiple interfaces just as VB.NET does.

The "problem" is that C# uses the same syntax for implementing an Interface
& Inheriting a class, namely the colon character ":" where as VB.NET uses
the cleaner, well at least more obvious, syntax of "Inherits" and
"Implements" to indicate you are implementing an interface verses inheriting
a class.


If you want true Multiple Inheritance of classes within .NET, then I would
recommend using Eiffel.NET (http://www.eiffel.com/), however I understand
that the multiple inheritance is only within Eiffel classes, and not the
..NET classes that it is able to expose. I also understand that it uses a
syntax to the VB.NET Implements syntax to avoid a couple of pitfalls of
Multiple Inheritance...

Hope this helps
Jay



Mahesh Naik said:
Use the relatively cleaner and newer language from the devil. Use C #.
It has all that Vb.net offers as a language and multiple inheritance
also. Be warned that the design time envirionment [I was informed , i
have not even tried] for c# may make you cry for ..mummy!..
<<snip>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top