Logic Belongs to Entities


Logic in Service

Think About Use-Case Only

  • a Price of each Product
  • Amount of each of Products

Moving Logic to Cart Entity

  • The logic sits together with data in the Cart entity, this leads to a rich model
  • The Cart doesn’t expose data (Items), Items are therefore properly encapsulated
  • This code is testable as we can mock the interface in tests to produce predictable prices
  • By the way, this was our goal — to have the logic in the entity

Interface Implementation

Only One Implementation

Moving Logic … even further






Developer interested in Domain-Driven Design & Modeling

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Day 8 | Cooldown System in Unity

Shadowed Box-Design

Why Timeszones Cause Amazon Seller Central Confusion

Reduce Cost and Increase Productivity with Value Added IT Services from buzinessware — {link} -

The journey from hours to story points on a real-world project

How to use Ansible modules on the remote host from the control node

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Svaťa Šimara

Svaťa Šimara

Developer interested in Domain-Driven Design & Modeling

More from Medium

Solid Principles:

Caching — Basic concept for next-level developers

Software Engineering in a nutshell

Legacy software series — Part 2— Software life cycles and software aging