Please help me understand the concept of how I can add functionality to an existing Interface class and its implementations with out breaking any previously released codes.
Here is the Interface Class
Here are the implementations
Here I have provided three implementations of the IShipmentProvid er but there may be more.
Now let just say I am supposed to add additional functionality of generating shipping label. How do I add the function of creating label to the interface class and implementations without breaking any other implementations . If I add the function directly to the interface then I will run into issue of breaking all the existing implementations unless I update all of them. Is there a way we can add the functionality with out breaking or updating existing implementations .
Please direct me to the right directions.
Thank you in advance.
Here is the Interface Class
Code:
Public Interface IShipmentProvider ReadOnly Property ProviderName As String ReadOnly Property ShipmentItems As ICollection(Of Package) Function GetRates() As ICollection(Of Rate) Function VerifyAddress(ByVal address As Address) As ICollection(Of Address) End Interface
Code:
Public Class FedExShipmentProvider Implements IShipmentProvider Public Function GetRates() As ICollection(Of Rate) Implements IShipmentProvider.GetRates Throw New NotImplementedException End Function Public ReadOnly Property ProviderName As String Implements IShipmentProvider.ProviderName Get Return "FedEx" End Get End Property Public ReadOnly Property ShipmentItems As ICollection(Of Package) Implements IShipmentProvider.ShipmentItems Get Return _lstofItems End Get End Property Public Function VerifyAddress(address As Address) As ICollection(Of Address) Implements IShipmentProvider.VerifyAddress Throw New NotImplementedException End Function End Class Public Class USPSShipmentProvider Implements IShipmentProvider Public Function GetRates() As ICollection(Of Rate) Implements IShipmentProvider.GetRates Throw New NotImplementedException End Function Public ReadOnly Property ProviderName As String Implements IShipmentProvider.ProviderName Get Return "USPS" End Get End Property Public ReadOnly Property ShipmentItems As ICollection(Of Package) Implements IShipmentProvider.ShipmentItems Get Return _lstofItems End Get End Property Public Function VerifyAddress(address As Address) As ICollection(Of Address) Implements IShipmentProvider.VerifyAddress Throw New NotImplementedException End Function End Class Public Class UPSShipmentProvider Implements IShipmentProvider Public Function GetRates() As ICollection(Of Rate) Implements IShipmentProvider.GetRates Throw New NotImplementedException End Function Public ReadOnly Property ProviderName As String Implements IShipmentProvider.ProviderName Get Return "UPS" End Get End Property Public ReadOnly Property ShipmentItems As ICollection(Of Package) Implements IShipmentProvider.ShipmentItems Get Return _lstofItems End Get End Property Public Function VerifyAddress(address As Address) As ICollection(Of Address) Implements IShipmentProvider.VerifyAddress Throw New NotImplementedException End Function End Class
Now let just say I am supposed to add additional functionality of generating shipping label. How do I add the function of creating label to the interface class and implementations without breaking any other implementations . If I add the function directly to the interface then I will run into issue of breaking all the existing implementations unless I update all of them. Is there a way we can add the functionality with out breaking or updating existing implementations .
Please direct me to the right directions.
Thank you in advance.
Comment