I have a dilemma. How to do better? I have a bunch of API interfaces and their implementations which use some specific frameworks/librarys which I would not like to expose. I cannot make a decision about whether to put both API interfaces and their implementation in the same package or split them up to different packages: one (or more) for the API and others for their implementation. Here is what I mean (simplified version):Single-package:Split-packages:In the first case we have API and imlementation in the same package which (may) simplify access to it. But in the second case we may also split it into a different jar file which would support more encapsulation from a particular implementation. Personally, I would choose splitting them up to different jar files in order to keep API in isolation from implementations.
Splitting API and Implementation among packages/jars
java;api
Well, I think the best guide are the Package Principles, and more specifically the three about package cohesion (what should be grouped into packages).Reuse-release equivalence principle (REP)Common-reuse principle (CRP)Common-closure principle (CCP)The first and the third offer some ground for splitting up the API and its implementation into different packages.For the first (REP), it can be argued that an implementation can have a different release cycle from the API (so they should not be in the same package)For the third (CCP), I think a stronger argument can be made. Since the API, as an abstraction, is more stable than the concrete implementation, and therefore will change for different reasons than the implementation, they should not be grouped into the same package.From the remaining principles (those of coupling) :Acyclic dependencies principle (ADP)Stable-dependencies principle (SDP)Stable-abstractions principle (SAP)it is clear that the second and third also implicitly argue for separating the API from the implementation.