带有继承的经典 ASP 类属性

发布于 2024-10-09 14:24:53 字数 1059 浏览 0 评论 0原文

我真的很想知道为什么这对我不起作用。我有两个类

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗失的美好 2024-10-16 14:24:53

问题是,每次访问 Customer 属性时,它都会创建一个新的

建议解决方案(未测试):

  private _Customer
  public property get Customer()
    if _Customer is nothing then
       set _Customer = new OrderCustomer
    end if
    set Customer = _Customer
  end property

The problem is that every time to access the Customer property it creates a new one

Proposed solution (not tested):

  private _Customer
  public property get Customer()
    if _Customer is nothing then
       set _Customer = new OrderCustomer
    end if
    set Customer = _Customer
  end property
弃爱 2024-10-16 14:24:53

酒店总是会接待新顾客。您应该将订单更改为类似的内容,

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

这将在创建订单时创建一个新的客户对象。

此外,这里发生的事情实际上并不是继承。客户只是订单的财产。

The property is always returning a new Customer. You should change order to something like

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文