Sometimes when I review code, I notice that there seems to exist a general lack of understanding of how interfaces and their implementers should be packaged up into components. Components are the unit of deployment. Java produces jar files, Ruby gems, .NET .dlls and with JavaScript, we deploy .js files.
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.BusinessLogic and 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 LibrarySystem.MongoDb component.
We are conscientious developers and want to create an extensible and pluggable system architecture.
Question: Into which component should we put IDatabase?
Here are our two choices again:
1.) We put interface IDatabase into LibrarySystem.BusinessLogic,
2.) Or we put IDatabase into LibrarySystem.MongoDb.
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.
Where Do Interfaces Live?
/by Olaf ThielkeWhere Do Interfaces Live?
Sometimes when I review code, I notice that there seems to exist a general lack of understanding of how interfaces and their implementers should be packaged up into components. Components are the unit of deployment. Java produces jar files, Ruby gems, .NET .dlls and with JavaScript, we deploy .js files.
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.BusinessLogic
andLibrarySystem.MongoDb
. The business logic component contains a high-levelApplication
class. ClassApplication
uses an interfaceIDatabase
to persist data to a database. At this stage,IDatabase
has only one implementer,MongoDbDatabase
, which resides in theLibrarySystem.MongoDb
component.We are conscientious developers and want to create an extensible and pluggable system architecture.
Question: Into which component should we put
IDatabase
?Here are our two choices again:
1.) We put interface
IDatabase
intoLibrarySystem.BusinessLogic
,2.) Or we put
IDatabase
intoLibrarySystem.MongoDb
.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.