我有一个严重的脑屁,为什么这不适合我。我有两个班级
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
我在这里缺少什么?我很确定我在以前的项目中做过这个。
答案 0 :(得分:0)
问题是每次访问Customer属性时都会创建一个新的
建议的解决方案(未经测试):
private _Customer
public property get Customer()
if _Customer is nothing then
set _Customer = new OrderCustomer
end if
set Customer = _Customer
end property
答案 1 :(得分:0)
该属性总是返回一个新客户。您应该将订单更改为
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
这将在创建订单时创建新的客户对象。
此外,这里发生的事情实际上并不是继承。客户只是订单的财产。