Domain Driven Design and Refactoring

This article is part of the serie: clean-code

Posted Jan 22, 2024
By Balázs HIDEGHÉTY
2 min reading time

We have reached the 3rd part of our quality code series—now, let’s talk about Domain-Driven Design (DDD). Why does it matter? Because we solve business problems, and DDD tackles communication, coding/structure, and complexities in the software industry for an easily maintainable, scalable solution.


Despite Object-Oriented Programming (OOP) being around for a while, the typical code written by many developers (around 2003) remained procedural and anemic. The prevalence of naming everything as “service,” “helper,” or “utils” resulted in what is known as anemic domain models, where the behavior and logic were scattered across the application, primarily residing in service classes rather than encapsulated within the objects themselves. The main classes were just pure POJOs, with public getter-setters, no encapsulation of state, and no behavior. This had implications for the clarity and maintainability of the code.


When I initially read the book, I was still in the early stages of my development career, but I quickly recognized the significant advantages that this design approach could bring.

Business-First Focus: The design emphasized prioritizing the business domain, aligning the software (and the language used) closely with the real-world problems it aimed to solve.

DDD’s Impact on Code Organization:

  • By reintroducing essential concepts, such as encapsulation (keeping behavior within objects), the need for excessive functional “service” components was minimized, resulting in code that became simpler and more organized.

  • By detaching code and business functions (domain logic) from other layers (persistence), we can significantly reduce complexity, improve testability, and facilitate easier maintenance.


Enough talk. Here are two videos to showcase DDD, both from Jimmy Bogard.

  1. Since DDD is also about modeling, let’s start with this one, so you can learn some of the basic concepts of it: Domain Driven Design: The Good Parts - Jimmy Bogard - YouTube

  2. As developers, we always aim to write better code. What better way to learn than by understanding how to convert (refactor) anemic code into something with behavior? Domain-Driven Refactoring - Jimmy Bogard - NDC London 2022 - YouTube


And finally, here’s the link to the book: Domain-Driven Design: Tackling Complexity in the Heart of Software


📌 Make sure you and your team subscribe (follow me) on  LinkedIn so you don’t miss out on the latest insights!


Further Reading
Designing Microservices the Right Way

Remember, business goals are rarely about having a top-notch system!

Finally, we have arrived at the point where we can discuss the pinnacle of modern software architecture: microservices.

Simple API - Integration Problems and Patterns

Even the simplest distributed system – yes, even integrating against a single API – can pose significant challenges (more than 80% of solutions that SMEs have). Mind-blowing, right!?

Distributed System Design and Fallacies

Distributed applications (APIs)? Avoid technical hiccups! Break free from misconceptions and build truly resilient distributed systems!