vendredi 18 septembre 2015

Separating interfaces and implementations

Suppose I have a project A, which references project B. B has some classes defined within it, and A has an interface ISomething, whose implementation situated in A, and uses B's classes. Then I want to create project C and another implementation of A's interface, which uses C's classes. Here's the problem: I want to move implementations of this interface to corresponding projects so that I can define which project I want to use in build script and omit other. Nevertheless I want to save connection between interface and it's implementation for sake of tons of already existing code that uses this interface. So far I've been thinking over following options:

  • Use adapter pattern in project A, which returns ISomething, references both implementations and adapts implementation of B if C is missing and vice versa. The con is that makes all interface-implementation relationship useless from my point of view
  • Create project D, which contains interface, and is referenced by A,B and C, and then resolve in this project the interface to one of it's implementation. A project receives concrete instance and works with it. The con is that I need to create another library and pollute repository.

What option is better and are there any others?

Aucun commentaire:

Enregistrer un commentaire