Comprehensive Domain Interface Design and Implementation in Java Backend Systems
This article explores comprehensive domain interface design in Java backend development, showing how to model domain objects as interfaces, implement repositories for JPA, MyBatis, and Elasticsearch, handle associations with JPA annotations, and apply these patterns in the open‑source Mallfoundry e‑commerce platform.
The article explains the concept of domain interface design, advocating the use of interfaces for domain models instead of concrete classes to enable seamless switching between different data sources such as JPA and MyBatis.
It provides Java code examples of defining a User interface, its implementation UserImpl , and repository implementations like JpaUserRepository with methods findById and save , illustrating how to map between persistence objects and domain objects.
Further, it discusses challenges when using Spring Data repositories with generic interfaces and shows a delegating repository pattern for Elasticsearch, including the DelegatingElasticsearchUserRepository class.
The article also covers association handling using JPA's targetEntity attribute in annotations such as @OneToMany , and alternative solutions for frameworks that lack this support, including custom mapping in MyBatis XML.
It demonstrates creating domain objects via a service method instead of the new operator, with a test method example.
Finally, it introduces the open‑source Mallfoundry e‑commerce platform, which applies these DDD and interface‑centric designs, and summarizes the benefits and required expertise for such architecture.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.