带有继承的经典 ASP 类属性
我真的很想知道为什么这对我不起作用。我有两个类
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
我在这里缺少什么?我很确定我在之前的项目中做到了这一点。
I'm having a serious brain fart as to why this isn't working for me. I have two classes
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
When I call the following code I get the result in the comments
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
What am I missing here? I was pretty sure I did this on previous projects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是,每次访问 Customer 属性时,它都会创建一个新的
建议解决方案(未测试):
The problem is that every time to access the Customer property it creates a new one
Proposed solution (not tested):
酒店总是会接待新顾客。您应该将订单更改为类似的内容,
这将在创建订单时创建一个新的客户对象。
此外,这里发生的事情实际上并不是继承。客户只是订单的财产。
The property is always returning a new Customer. You should change order to something like
This will create a new customer object when an order is created.
Additionally, what is happening here isn't actually inheritance. Customer is just a property of the Order.