与继承相关的问题(多个) [英] Question Related to Inheritance( multiple)

查看:94
本文介绍了与继承相关的问题(多个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在寻找解决问题的方法。这与继承有关

(以多个数量继承基类的属性)。我用VB.net语言编写了

代码,我有两个类clsVehicle和clsWheel。

clsWheel有两个属性直径和压力。 clsVehicle有两个

属性Name和Make。我希望以这种方式实现这些类


创建一个Vehicle类的对象。


dim Ovehicle as new clsVehicle


现在我想要一个这样的陈述


实现代码。


Ovehicle.name =" VehicleName"


Ovehicle.make =" VehicleMake"

Ovehicle.wheels.count = 4


Ovehicle.wheel(1).diameter =" 100"


Ovehicle.wheel(2).diameter =" 100"


Ovehicle.wheel(3).diameter =" 100"


Ovehicle.wheel(4).diameter =" 100"


在这些

类中必须实现哪些属性和其他代码,以便我可以使上述所有语句都有效。可以任何一个

帮我写这段代码。我在这里粘贴课程代码。我用

尝试使用参数化属性,但我失败了。我尝试使用这个

语句继承cls Vehicle中的clsWheel。我也尝试在clsVehicle dim owheel()中创建实例

clswheel作为clswheel。


请指导我实现这个目标


Public Class clsVehicle


私人mname为字符串


私人mmake为字符串


公共属性名称()为字符串


获取


返回mname


结束获取


套装(ByVal Value As String)


mname =价值


结束套件

结束物业


Public Property Make()As String


获取


返回mmake


结束获取


设置(ByVal Value As String)


mmake =价值


结束套件


结束物业


结束等级

公共舱clsWheels


私人mDiam字符串


私人压力作为字符串


公共财产直径()作为String


获取


返回mDiam


结束获取

套装(ByVal Value As String)


mDiam =价值


套装


结束物业


公共财产压力()为字符串


获取


返回压力


结束获取


设定(ByVal Value As String)


mpressure = Value < br $>

结束套装


结束物业


结束班级


Tia,


Kishor

Hi,

I am looking for the solution to my problem. this is related to inheritance
(Inheriting properties of base class in multiple quantity) . I am writing
code in VB.net language, I am having two classes clsVehicle and clsWheel.
clsWheel has two properties diameter and pressure. clsVehicle has two
properties Name and Make. I want to implement these classes this way

create a object of Vehicle class.

dim Ovehicle as New clsVehicle

Now I want to have a statements like this

implementation code.

Ovehicle.name = "VehicleName"

Ovehicle.make= "VehicleMake"

Ovehicle.wheels.count = 4

Ovehicle.wheel(1).diameter = "100"

Ovehicle.wheel(2).diameter = "100"

Ovehicle.wheel(3).diameter = "100"

Ovehicle.wheel(4).diameter = "100"

What are the properties and other code has to be implemented in these
classes so that I can have all these above statements valid. Can any one
help me writing this code. I am here pasting the code of the class. I have
tried using parameterized properties but I failed. I tried using this
statement inherits clsWheel in cls Vehicle. I also tried creating instance
of clswheel in clsVehicle dim owheel() as clswheel.

Please guide me to achieve this

Public Class clsVehicle

Private mname As String

Private mmake As String

Public Property name() As String

Get

Return mname

End Get

Set(ByVal Value As String)

mname = Value

End Set

End Property

Public Property Make() As String

Get

Return mmake

End Get

Set(ByVal Value As String)

mmake = Value

End Set

End Property

End Class

Public Class clsWheels

Private mDiam As String

Private mpressure As String

Public Property Diameter() As String

Get

Return mDiam

End Get

Set(ByVal Value As String)

mDiam = Value

End Set

End Property

Public Property pressure() As String

Get

Return mpressure

End Get

Set(ByVal Value As String)

mpressure = Value

End Set

End Property

End Class

Tia,

Kishor

推荐答案

我不认为这是继承,更多的问题。无论如何继承人

wat我做(我确实把单独的类放在单独的文件中,所以我不知道这是否会给出编译顺序问题)

您的clsvehicle中的
声明


私人wheel1作为新clsWheel


并为其创建一个属性

Public Property wheel()as clsWheel

获取

返回wheel1

结束获取

Set (ByVal Value As clsWheel)

wheel1 =价值

结束套件

结束物业


然后你得到一个Ovehicle.wheel.diameter ......


没有完成这个w数组,但我认为它可以像宣布

weel1一样简单阵列


希望它有所帮助


eric


" Kishor" < ***的Kp @ hotmail.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
I don''t think that this is inheritance, more of a oo question. anyway heres
wat i do (i do put seperate classes in seperate files so i dont know if this
would give compilation order problems)

in your clsvehicle declare

private wheel1 as new clsWheel

and make a property for it

Public Property wheel() As clsWheel
Get
Return wheel1
End Get
Set(ByVal Value As clsWheel)
wheel1 = Value
End Set
End Property

then you get a Ovehicle.wheel.diameter ...

havent done this w arrays but i think it could be as simple as declaring the
weel1 as an array

hope it helps

eric

"Kishor" <Kp***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...


我正在寻找解决问题的方法。这与
继承有关(以多个数量继承基类的属性)。我用VB.net语言编写代码,我有两个类clsVehicle和clsWheel。
clsWheel有两个属性直径和压力。 clsVehicle有两个属性Name和Make。我希望以这种方式实现这些类
Hi,

I am looking for the solution to my problem. this is related to inheritance (Inheriting properties of base class in multiple quantity) . I am writing
code in VB.net language, I am having two classes clsVehicle and clsWheel.
clsWheel has two properties diameter and pressure. clsVehicle has two
properties Name and Make. I want to implement these classes this way



" Kishor" < ***的Kp @ hotmail.com> schrieb
"Kishor" <Kp***@hotmail.com> schrieb


我正在寻找解决问题的方法。这与
继承有关(以多个数量继承基类的属性)。我用VB.net语言编写代码,我有两个类clsVehicle和clsWheel。 clsWheel有两个属性直径和压力。 clsVehicle有两个属性Name和Make。我想以这种方式实现这些类
Hi,

I am looking for the solution to my problem. this is related to
inheritance (Inheriting properties of base class in multiple
quantity) . I am writing code in VB.net language, I am having two
classes clsVehicle and clsWheel. clsWheel has two properties diameter
and pressure. clsVehicle has two properties Name and Make. I want to
implement these classes this way




未经测试,但它应该有效:(注意:轮指数从零开始)

Dim Ovehicle As new clsVehicle


Ovehicle.name =" VehicleName"

Ovehicle.Make =" VehicleMake"

Ovehicle.Wheels.Count = 4

Ovehicle.Wheels(0).Diameter =" 100"

Ovehicle.Wheels(1).Diameter =" 100" ;

Ovehicle.Wheels(2).Diameter =" 100"

Ovehicle.Wheels(3).Diameter =" 100"

Public Class clsVehicle

私人mname为字符串

私人mmake为字符串

公共只读轮子为新clsWheels

公共财产名称()作为字符串

获取

返回mname

结束获取

Set( ByVal Value As String)

mname =价值

结束集

结束物业

Public Property Make()As字符串

获取

返回mmake

结束获取

设置(ByVal值为字符串)

mmake =价值

结束设置

结束物业

结束类


公共类clsWheels

私有mItems作为新ArrayList

默认公共ReadOnly属性项(_

ByVal索引为整数)as clsWheel


获取

返回DirectCast(mItems(Index),clsWheel)

结束获取

结束财产

公共财产计数()作为整数

获取

返回mItems.Count

结束获取

设置(ByVal值为整数)

如果Value = mItems.Count然后返回

如果值< mItems.Count然后

mItems.RemoveRange(Value,mItems.Count - Value)

Else

Dim i As Integer

For i = mItems.Count + 1 To Value

mItems.Add(New clsWheel)

Next

End If

结束套件

结束物业


结束班级


公共班级clsWheel

私人mDiam As String

私人压力作为字符串

公共财产直径()为字符串

获取

返回mDiam

结束获取

设置(ByVal值为字符串)

mDiam =价值

结束集

结束物业

公共财产压力()作为字符串

获取

返回压力

结束获取

套装(ByVal价值为字符串)

mpressure =价值

结束套件

结束物业

结束班

顺便说一句,问题不在于继承。 :-)

-

Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html



Untested, but it should work: (note: wheel index is zero-based)
Dim Ovehicle As New clsVehicle

Ovehicle.name = "VehicleName"
Ovehicle.Make = "VehicleMake"
Ovehicle.Wheels.Count = 4
Ovehicle.Wheels(0).Diameter = "100"
Ovehicle.Wheels(1).Diameter = "100"
Ovehicle.Wheels(2).Diameter = "100"
Ovehicle.Wheels(3).Diameter = "100"

Public Class clsVehicle
Private mname As String
Private mmake As String
Public ReadOnly Wheels As New clsWheels
Public Property name() As String
Get
Return mname
End Get
Set(ByVal Value As String)
mname = Value
End Set
End Property
Public Property Make() As String
Get
Return mmake
End Get
Set(ByVal Value As String)
mmake = Value
End Set
End Property
End Class

Public Class clsWheels
Private mItems As New ArrayList
Default Public ReadOnly Property Item( _
ByVal Index As Integer) As clsWheel

Get
Return DirectCast(mItems(Index), clsWheel)
End Get
End Property
Public Property Count() As Integer
Get
Return mItems.Count
End Get
Set(ByVal Value As Integer)
If Value = mItems.Count Then Return
If Value < mItems.Count Then
mItems.RemoveRange(Value, mItems.Count - Value)
Else
Dim i As Integer
For i = mItems.Count + 1 To Value
mItems.Add(New clsWheel)
Next
End If
End Set
End Property

End Class

Public Class clsWheel
Private mDiam As String
Private mpressure As String
Public Property Diameter() As String
Get
Return mDiam
End Get
Set(ByVal Value As String)
mDiam = Value
End Set
End Property
Public Property pressure() As String
Get
Return mpressure
End Get
Set(ByVal Value As String)
mpressure = Value
End Set
End Property
End Class
BTW, the question is not about inheritance at all. :-)
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html


hi,

感谢您的即时回复。我也试过这个。根据你的代码我

一次只能获得一个对象。如果我宣布它是arry

你的声明

私人wheel1作为新clsWheel

变成这样

private wheel1()as new clsWheel

但这在vb.net中是不允许的。要做到这一点,我们必须改变代码这个

的方式......

私有wheel1作为New Hashtable(),你写这个的那一刻就增加了

手动创建和销毁对象的开销。我想避免

这个。有什么方法可以让我实现这个我在

第一封邮件中所说的。


Tia。

Kishor



" EricJ" <ericRéMo** @ ThiSomnipack.be>在消息中写道

news:3f ********************** @ reader0.news.skynet。是...

Thanks for your immediate reply. I have tried this also. as per your code I
wll get only one object at a time. If I am declaring it as a arry
Your Statement
private wheel1 as new clsWheel
become like this
private wheel1() as new clsWheel
but this is not allowed in vb.net. to do this we have to change code this
way....
private wheel1 As New Hashtable() and the moment you write this it adds
overhead of creating and destroying the objects manually. I want to avoid
this. is there any way which will allow me to achieve this what I said in
first mail.

Tia.
Kishor


"EricJ" <ericRéMo**@ThiSomnipack.be> wrote in message
news:3f**********************@reader0.news.skynet. be...
我不认为这是继承,更多的是一个问题。无论如何
heres wat我做的(我确实把单独的类放在单独的文件中,所以我不知道
这会给编译顺序问题)

在你的clsvehicle声明

私人wheel1作为新的clsWheel

并为它制作一个属性

公共财产轮()as clsWheel
获取
返回wheel1 <结束获取
设置(ByVal值为clsWheel)
wheel1 =值
结束集
结束属性

然后你得到一个Ovehicle.wheel .diameter ......

没有完成这个w数组,但我认为它可以像宣布
weel1作为一个数组一样简单

希望它能帮助

eric

Kishor < ***的Kp @ hotmail.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
I don''t think that this is inheritance, more of a oo question. anyway heres wat i do (i do put seperate classes in seperate files so i dont know if this would give compilation order problems)

in your clsvehicle declare

private wheel1 as new clsWheel

and make a property for it

Public Property wheel() As clsWheel
Get
Return wheel1
End Get
Set(ByVal Value As clsWheel)
wheel1 = Value
End Set
End Property

then you get a Ovehicle.wheel.diameter ...

havent done this w arrays but i think it could be as simple as declaring the weel1 as an array

hope it helps

eric

"Kishor" <Kp***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...


我正在寻找解决问题的方法。这与
Hi,

I am looking for the solution to my problem. this is related to


继承

(以多个数量继承基类的属性)有关。我是
用VB.net语言编写代码,我有两个类clsVehicle和
clsWheel。 clsWheel有两个属性直径和压力。 clsVehicle有两个属性Name和Make。我想以这种方式实现这些类
(Inheriting properties of base class in multiple quantity) . I am writing code in VB.net language, I am having two classes clsVehicle and clsWheel. clsWheel has two properties diameter and pressure. clsVehicle has two
properties Name and Make. I want to implement these classes this way




这篇关于与继承相关的问题(多个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆