我有两个班,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
属性。
我需要做的是当对象是 aCellphoneCustomerService
时,基类应该使用该类的 shadowedCustomerRepository
属性,CellphoneCustomerService
但如果对象是一个CustomerService
类,它将使用它自己的CustomerRepository
属性。