我有两个课程,CustomerService class
和CellphoneCustomerService
课程。从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方法,GetAllCustomers
和GetCustomer
函数时,它仍使用CustomerRepository
基类的属性,而不是派生类的带阴影的CustomerRepository
属性。
我需要做的是当对象是CellphoneCustomerService
时,基类应该使用CustomerRepository
类的带阴影的CellphoneCustomerService
属性,但是如果对象是{{1}它将使用自己的CustomerService
属性。