Inheritance 具有继承的经典ASP类属性
我脑子里一直在放屁,为什么这对我不起作用。我有两节课Inheritance 具有继承的经典ASP类属性,inheritance,asp-classic,Inheritance,Asp Classic,我脑子里一直在放屁,为什么这对我不起作用。我有两节课 class Order private Test_1 private oCustomer public property get Test() Test= Test_1 end property public property let Test( value ) Test_1 = value end property public property get Customer() if (
class Order
private Test_1
private oCustomer
public property get Test() Test= Test_1 end property
public property let Test( value ) Test_1 = value end property
public property get Customer()
if ( NOT isObject( oCustomer ) ) then
set oCustomer = new OrderCustomer
end if
set Customer = oCustomer
end property
end class
class OrderCustomer
private FirstName_1
public property get FirstName() FirstName = FirstName_1 end property
public property let FirstName( value ) FirstName_1 = value end property
end class
当我调用下面的代码时,我会在注释中得到结果
set oOrder = new Order
oOrder.Test = "Hi"
response.write oOrder.Test() 'writes out "HI"
oOrder.Customer.FirstName = "Fred" 'does actually set it to this value, I am able to response.write out FirstName_1 after it is set in let
response.write oOrder.Customer.FirstName() 'writes out nothing
set oOrder = nothing
我错过了什么?我很确定我在以前的项目中做过这件事。问题是,每次访问客户属性时,它都会创建一个新属性 建议的解决方案(未测试):
问题是,每次访问客户属性时,它都会创建一个新属性 建议的解决方案(未测试):
酒店总是会返回新客户。你应该把订单改成
class Order
private m_Customer
private sub Class_Initialize()
set m_Customer = new Customer
end sub
public property get Customer()
set Customer = m_Customer
end property
end class
这将在创建订单时创建一个新的customer对象
此外,这里发生的事情实际上并不是继承。客户只是订单的一个属性。该属性总是返回一个新客户。你应该把订单改成
class Order
private m_Customer
private sub Class_Initialize()
set m_Customer = new Customer
end sub
public property get Customer()
set Customer = m_Customer
end property
end class
这将在创建订单时创建一个新的customer对象
此外,这里发生的事情实际上并不是继承。客户只是订单的一个属性。我的代码中确实有这一点,只是没有将其放在上面的示例中。如果(不是isObject(oCustomer)),那么设置oCustomer=new OrderCustomer end,如果设置Customer=oCustomer。哈哈,我更新了代码以显示它没有重新创建自己,并注意到我正在检查oCustomer[s]是否是对象而不是oCustomer。Le叹气…我确实在代码中有这个,只是没有把它放在上面的示例中。如果(不是isObject(oCustomer)),那么设置oCustomer=new OrderCustomer end,如果设置Customer=oCustomer。哈哈,我更新了代码以显示它没有重新创建自己,并注意到我正在检查oCustomer[s]是否是对象而不是oCustomer。Le叹气…哈哈,我更新了代码以显示它没有重新创建自己,并注意到我正在检查oCustomer[s]是否是一个对象而不是oCustomer。唉……别担心。以SO问题的形式写出问题的行为通常会得到答案。哈哈,我更新了代码,以表明它没有重新生成,并注意到我正在检查oCustomer[s]是否是一个对象而不是oCustomer。唉……别担心。以问题的形式写出问题的行为通常会得到答案。