Here’s my current set-up:
Public Interface IDatabase
Function CreateParameter(name as String, dbType as <dbTypeEnumeration>)
End Interface
Public Class OracleDatabaseRepository
Implements IDatabase
Public Function CreateParameter(ByVal name As String, ByVal dbtype As <dbTypeEnumeration>) As Object
End Function
End Class
Public Class SQLServerRepository
Implements IDatabase
Public Function CreateParameter(ByVal name As String, ByVal dbtype As <dbTypeEnumeration>) As Object
End Function
End Class
Public Class DatabaseService
Private _rep As IDatabase
Sub New(ByRef rep As IDatabase)
_rep = rep
End Sub
Public Function CreateParameter(ByVal name As String, ByRef dbtype As <dbTypeEnumeration>) As Object
_rep.CreateParameter(name, dbtype)
End Function
End Class
The problem here is what exactly is dbTypeEnumeration. In the example above, it’s simply a placeholder to what my problem is. Since we use both Oracle and SQL Server databases, the DbTypes are different depending on the database being used. For Oracle, the OracleClient object has its own OracleDbType enumeration with types. SQL Server also has its own enumeration.
My question is: is it possible to show those database-specific enumerations depending on which repository is injected into the DatabaseService constructor? If not, what’s the best way to go about this? I want to separate the two databases, share logic, and allow for future development, ala the interface as a code contract for that development.
Repository implementation correctness asside, I’d change the level of
DbTypeabstraction.This
interfaceis db agnostic.The db constrained implementation should be in your concrete
Repositoryitself. How else would you want to keep it generic but still differ between the two types?