In 95% of examples I see, people are adding @Entity
or @Document
annotations to their domain objects.
I would like to create an app in which I can easily change persistence layer. It should be possible to switch in settings from SQL DB
to e.x. MongoDB
etc.
I want to keep my domain objects completely independent from persistence layer.
I have thought about something like this:
Where Item
is a domain object.
public interface ItemsRepository {
List<Item> getItems();
}
Each ItemsRepository
implementation has it's own dedicated persistence layer object. For SQL it will be let's say ItemEntity
class, for Mongo ItemDocument
class. And each persistence object has conversion from and to domain object.
Is approach like this acceptable? If not, what are the best industry patterns to solve that problem?
Aucun commentaire:
Enregistrer un commentaire