I’m mostly speaking about Java and classical OOP. Say I’m using DAO pattern. So I create interfaces like CustomerDao, AccountDao and others. I would place then into org.example.dao package:
org.example.dao.CustomerDao
org.example.dao.AccountDao
...
This all seems good to me so far. Then I create implementations for these interfaces. Here rises my first question: How do I name them? One practice that I have seen is to use *Impl postfix like CustomerDaoImpl. Or perhaps the name should reflect the nature of the implementation, e.g. AccountDatabaseDao or DatabaseBasedAccountDao? Or may be the name should be left intact and then the package would describe the nature of these implementations? If you suggest one or another way, then where should those implementations be placed? A separate package (what naming logics?) or the same package?
There are two camps: functional and technical naming.
The one like:
The other like:
I personally like to have the interface and the implementations in one spot and make only the interface public and to package by functionality as the packages have a higher cohesion this way.
With growing size you can still split the packages in for example
org.example.customer.dao,org.example.customer.serviceandorg.example.customer.ui. (Technically this is the same asorg.example.dao.customer.dao,org.example.service.customerandorg.example.ui.customeras Java packages are not nested.)For your example I’d start with:
To make the implementation package private you need a factory to create the instances. If you’re using DI. The DI-framework implements the factory for you and you can inject the instances in the users classes that depend only on the interface contract.