在基类中使用派生类的shadowed属性

时间:2013-04-25 12:33:38

标签: vb.net oop inheritance shadow

我有两个课程,CustomerService classCellphoneCustomerService课程。从CellphoneCustomerServic类派生的CustomerService类。 CellphoneCustomerService类会隐藏CustomerRepository类的CustomerService属性。

Public Class CustomerService
        <Microsoft.Practices.Unity.Dependency()> _
        Public Property CustomerRepository as ISQLRepository
            Set (Byval value As SQLRepository)
                _customerRepository = value
            End Set         
            Get 
                Return _customerRepository
            End Get
        End Property


        Public Sub Save(Byval Cust As Customer)
            Me.CustomerRepository.Save(object)
        End Sub

        Public Function GetAllCustomers(Byval Query As String) As Customer
            Me.CustomerRepository.GetAllCustomer(Byval Query As String)
        End Sub

        Public Function GetCustomer(Byval ID As Integer)
            Me.CustomerRepository.GetCustomer(object)
        End Sub             
End Class


Public Class CellphoneCustomerService
    Inherits CustomerService
        <Microsoft.Practices.Unity.Dependency()> _
        Public Shadow Property CustomerRepository As IOracleRepository
            Set (Byval value As OracleRepository)
                _customerRepository = value
            End Set         
            Get 
                Return _customerRepository
            End Get
        End Property            
End Class

我对此代码的问题是,当我创建CellphoneCustomerService类的实例并使用Save方法,GetAllCustomersGetCustomer函数时,它仍使用CustomerRepository基类的属性,而不是派生类的带阴影的CustomerRepository属性。

我需要做的是当对象是CellphoneCustomerService时,基类应该使用CustomerRepository类的带阴影的CellphoneCustomerService属性,但是如果对象是{{1}它将使用自己的CustomerService属性。

0 个答案:

没有答案