Au début, un projet est petit :
Puis :
Sans structure, le projet devient fragile.
Quand le domaine dépend directement de Spring/JPA :
Le métier au centre (le “domaine”). Autour : des adaptateurs.
[ Web/API ] -> [ Application ] -> [ Domaine ] <- [ DB/JPA ]
Port :
public interface ChienStore { Chien save(Chien chien); Optional<Chien> findByTatouage(String tatouage); }
Adaptateur JPA :
@Repository public class ChienJpaStore implements ChienStore { private final ChienRepository repo; public ChienJpaStore(ChienRepository repo) { this.repo = repo; } @Override public Chien save(Chien chien) { return repo.save(chien); } @Override public Optional<Chien> findByTatouage(String tatouage) { return repo.findByNumeroTatouage(tatouage); } }
Service métier dépend du port :
public class RegisterChienUseCase { private final ChienStore store; public RegisterChienUseCase(ChienStore store) { this.store = store; } public void register(...) { ... } }
✅ tests faciles (mock du port) ✅ domaine “pur” ❌ plus de fichiers ❌ nécessite discipline
Si petit projet pédagogique : optionnelle.
RaceStore