I wrote a rather complex application application that used the first example and here is how I justified the design. In my case there was a common interface related to pricing an underwriting case, but several vendors who could provide different web services that would fill in the actual data. This was the package structure
com.example.pricing
\IPricingProvider.java
\AbstractPriceProvider.java
com.example.pricing.vendorA
\PricingEngine.java
com.example.pricing.vendorB
\PricingEngine.java
com.example.pricing.vendorC
\PricingEngine.java
Then in my code I used the import
to wire the engine I wanted. Like this:
import com.example.pricing.*;
import com.example.pricing.vendorB.*;
IPricingProvider provider = Engine.create();
The advantages for me were the ability to have complex and messy implementations for each vendor (two were rest based one was a Web Service using wsimport
so there was a lot of generated Java files) and not make Eclipse auto-complete look like a total nightmare. Also it made it easier to hand over a single vendor to a different developer.