Skip to content
TopicTracker
From HackerNewsView original
TranslationTranslation

The dogma of entity-based Services and Repositories

Martin Fowler critiques the rigid pattern of entity-based services and repositories, arguing it often leads to an anemic domain model where business logic is pushed into services. He advocates for a richer domain model where logic lives within entities, with services reserved for coordinating cross-entity workflows.

Background

Martin Fowler is a famous software architect and author of the "Patterns of Enterprise Application Architecture" catalog, a standard reference for backend application design. - The "Service Layer" pattern places business logic between the UI and data-access layers, handling transactions, rules, and coordination. - The page warns against the common mistake of building services that mirror database tables (e.g., one Service + Repository per entity like User/Order). This creates thin, anemic wrappers that just pass data through. - The better approach: organize services around real business use cases (SubmitOrder, CancelBooking), not database entities. Services should embody business operations, not CRUD actions.