I have two libraries in a 3-tier project – call them BO and DAL. Almost every class in DAL implements a Save Method:
Public Function Save(ByVal someObject As BO.SomeType) As Boolean
As I have to add the missing Save methods, I though it was a good idea to create an interface which implements a ‘MustInherit Save’ function. So if I type:
MustOverride Function Save(ByVal someObject As BO.SomeType) As Boolean
That should do the trick; but the type of the parameter is always different. For example, in class DAL.TypeA:
Public Function Save(ByVal someObject As BO.SomeTypeA) As Boolean
And in class DAL.TypeB:
Public Function Save(ByVal someObject As BO.SomeTypeB) As Boolean
Is there a way to handle different type of parameters in an interface? Some kind of generic? Is this even possible?
Perfect use case for generics.
Using a generic interface:
Interface:
Implementation:
Or, using a generic base class instead of an interface
Base class
Implementation