0

我有两个班,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属性。

我需要做的是当对象是 aCellphoneCustomerService时,基类应该使用该类的 shadowedCustomerRepository属性,CellphoneCustomerService但如果对象是一个CustomerService类,它将使用它自己的CustomerRepository属性。

4

0 回答 0