Where Do Interfaces Live?
Note: Not all interfaces divide functionality up into separate components. We only use interfaces in this manner when we aspire to have pluggable components.
Say, we have an interface, and two classes, an implementer of the interface, and a consumer of the interface. If the classes (interface implementer and interface consumer) are located in different components, then where should the interface go? Should it go into the component with the interface consumer or should we place it into the component that contains the implementer?
Let’s get more concrete with an example. Say, we are developers on a library management system. In this system, we have two components,
LibrarySystem.MongoDb. The business logic component contains a high-level
Application class. Class
Application uses an interface
IDatabase to persist data to a database. At this stage,
IDatabase has only one implementer,
MongoDbDatabase, which resides in the
We are conscientious developers and want to create an extensible and pluggable system architecture.
Question: Into which component should we put
Here are our two choices again:
1.) We put interface
2.) Or we put
Which one makes more sense? And why?
Please email me your answers. The person with the best explanation receives a free cup of coffee. If you’re in Auckland, I am happy to meet you and have it in person. If you live elsewhere, I’ll send you $5, and I am happy to do a Google Meet session over that cup of coffee (or beverage of your choice). I’m curious to hear your ideas about software engineering.
Until tomorrow when I will reveal the answer.