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

Serving Static Content with Amazon S3 & CloudFront

Python tips and tricks

Gamedev: Parallax

My Period between College Graduation and Studying Abroad

Challenge: Fetch Order from Server

Domain Driven Design in Data Engineering Part 3: Reboot

Develop Fraud detection with python

Day 8 | Cooldown System in Unity

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

The Pragmatic Programmer EP.9 — Before a project begin

Software Development Vs Software Engineering: Understanding The Key Differences

Commits are to Code what Save Games are to Video Games

Image showing the text “Keep calm and reset to last checkpoint”

Strategy Design Pattern