By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

How to add functionality to an existing Interface Class and Implementations

Expert 100+
P: 210
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
Expand|Select|Wrap|Line Numbers
  1. Public Interface IShipmentProvider
  2.     ReadOnly Property ProviderName As String
  3.     ReadOnly Property ShipmentItems As ICollection(Of Package)
  4.     Function GetRates() As ICollection(Of Rate)
  5.     Function VerifyAddress(ByVal address As Address) As ICollection(Of Address)
  6. End Interface
  7.  
Here are the implementations
Expand|Select|Wrap|Line Numbers
  1. Public Class FedExShipmentProvider
  2.     Implements IShipmentProvider
  3.  
  4.     Public Function GetRates() As ICollection(Of Rate) Implements IShipmentProvider.GetRates
  5.         Throw New NotImplementedException
  6.     End Function
  7.  
  8.     Public ReadOnly Property ProviderName As String Implements IShipmentProvider.ProviderName
  9.         Get
  10.             Return "FedEx"
  11.         End Get
  12.     End Property
  13.  
  14.     Public ReadOnly Property ShipmentItems As ICollection(Of Package) Implements IShipmentProvider.ShipmentItems
  15.         Get
  16.             Return _lstofItems
  17.         End Get
  18.     End Property
  19.  
  20.     Public Function VerifyAddress(address As Address) As ICollection(Of Address) Implements IShipmentProvider.VerifyAddress
  21.         Throw New NotImplementedException
  22.     End Function
  23. End Class
  24.  
  25.  
  26. Public Class USPSShipmentProvider
  27.     Implements IShipmentProvider
  28.  
  29.     Public Function GetRates() As ICollection(Of Rate) Implements IShipmentProvider.GetRates
  30.         Throw New NotImplementedException
  31.     End Function
  32.  
  33.     Public ReadOnly Property ProviderName As String Implements IShipmentProvider.ProviderName
  34.         Get
  35.             Return "USPS"
  36.         End Get
  37.     End Property
  38.  
  39.     Public ReadOnly Property ShipmentItems As ICollection(Of Package) Implements IShipmentProvider.ShipmentItems
  40.         Get
  41.             Return _lstofItems
  42.         End Get
  43.     End Property
  44.  
  45.     Public Function VerifyAddress(address As Address) As ICollection(Of Address) Implements IShipmentProvider.VerifyAddress
  46.         Throw New NotImplementedException
  47.     End Function
  48. End Class
  49.  
  50. Public Class UPSShipmentProvider
  51.     Implements IShipmentProvider
  52.  
  53.     Public Function GetRates() As ICollection(Of Rate) Implements IShipmentProvider.GetRates
  54.         Throw New NotImplementedException
  55.     End Function
  56.  
  57.     Public ReadOnly Property ProviderName As String Implements IShipmentProvider.ProviderName
  58.         Get
  59.             Return "UPS"
  60.         End Get
  61.     End Property
  62.  
  63.     Public ReadOnly Property ShipmentItems As ICollection(Of Package) Implements IShipmentProvider.ShipmentItems
  64.         Get
  65.             Return _lstofItems
  66.         End Get
  67.     End Property
  68.  
  69.     Public Function VerifyAddress(address As Address) As ICollection(Of Address) Implements IShipmentProvider.VerifyAddress
  70.         Throw New NotImplementedException
  71.     End Function
  72.  
  73. End Class
  74.  
  75.  
Here I have provided three implementations of the IShipmentProvider 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.
Apr 16 '14 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 210
Any help would be really appreciated.
Apr 17 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.