I have an interface to communicate with a DB (actually it is not a database, but this is to give a concrete example):
interface DbInterface{
Result sendQuery(Query q);
}
And I am trying to improve reusability by separating specific components into individual projects:
- App1, an application that requires access to a database
- App2, an application that requires access to a database
- DB1, a concrete implementation of DbInterface (let's say SQL)
- DB2, a concrete implementation of DbInterface (let's say using some NoSql database)
How do you typically design such an architecture and where should DbInterface
be located?
- in one of the applications? but that means all other three component depend on that project to access the interface - does not sound right
- in one of the DB implementations? same - does not sound right.
- in both DB implementations? code duplication.
- in a separate project, which would only contain that interface? seems abusive to include a dependency for one interface only.
For reference, this is Java + maven, but the issue is fairly generic I suppose.