A Discussion on Domain Driven Design

X Driven Development, is what we use to determine if the software we are building works in accordance with what we expect it to do.  But how do we know what we are building is in accordance with the actual business domain?  Do you look to the 500 page requirements document for the answers?  Do you look at the wire frame that looks nothing like what you have actually designed?  Do you trust the acceptance test that the product owner has authored and believes this is the way it should work?  What do you do? 

Domain Driven Design complements X Driven Development as well as other agile software development practices by bringing to light the business model that the software is complimenting. By incorporating a model driven approach to software development we enlighten ourselves as well as the product owners and all additional stakeholders on how the system should behave and solve the business need.

I believe that we should extend the already proven design methodology of Test Driven Development of “Red, Green, Refactor” by rephrasing it to “Model, Red, Green, Refactor, Refine”.

  • Model: Construct a domain model based on DDD principles.
  • Red: Write failing test or specifications that govern the intended behavior of the model.
  • Green: Write just enough code to make the specification or test pass.
  • Refactor: Refactor the passing code to design patterns that simplify the composition of the code decreasing technical debt.
  • Refine: Refine the model to greater incite based on the code you have written and verify with the product owner.
  • Start Again.

Before I go any further let’s look at just what Domain Driven Design is.

I am not going to lie to any of you, when I first picked up Eric Evans book 2 years ago. I read it from cover to cover in about a week. When I was done I reflected on what I had read and nothing seemed to stick. I constantly had to read and reread chapters to figure out how Eric’s practices applied to my code. After all I have the TDD and refactoring stuff down how bad could it be? Well fast forward 3 months and I still didn’t quiet grasp many of the concepts. Now I don’t know what happened but one day I had an epiphany reread it again but this time pause after each chapter and reflect on your current architecture but not at the code level but from the business DOMAIN level. Eureka!! Now it all made sense. My code looks nothing like the domain. Don’t get me wrong I had classes that represented entities but the entities themselves weren’t cohesive from the contextual modularization of the domain. Not to mention the Ubiquitous language didn’t exist. Two years later and after rereading DDD for the third time and holding several training seminars I finally got it down.

You know they say a picture is worth a thousand words.  So I would like introduce you to the navigational map of the Model Driven Design.

Model Driven Design is broken down into the following artifacts:

Each one of these artifacts complements one another and allows us to gain greater insight into the business domain. But before we start talking about these artifacts it is important to note that there is a backbone or glue rather that holds all these artifacts together. It is somewhat of an ethereal force that when applied correctly brings clarity to all that view the model but when not used correctly can wreak havoc and leave a sour taste with everyone involved in domain driven design. Ok that was a little too deep even for me. This glue is referred to as the “Ubiquitous Language”.

“A domain model can be the core of a common language for a software project. The model is a set of concepts built up in the heads of people on the project, with terms and relationships that reflect domain insight. These terms and interrelationships provide the semantics of a language that is tailored to the domain while being precise enough for technical development. This is a crucial cord that weaves the model into development activity and binds it with the code.” Evans 2003

The ubiquitous language forms a common thread where the names of classes and specific business operations or constraints are given a common terms that have been brought to fruition by the domain model and agreed upon by ALL stakeholders.

For instance in some development groups you are given a requirement. In the requirement it mentions that a potential clients, contact information be stored in the system. Having worked on many CRM systems, you create a class named “Lead”. Other members of the team create another object named “Contact”. Now let’s examine the paradox. You have 3 entities that mean the same thing.

  • Potential Client
  • Lead
  • Contact

Now when you have a conversation with the product owner and they mention the term “potential client”, you have two options. Rudely correct him by saying “you mean Lead” of which you will get a blank stare followed by “Well what every YOU call it. Yeah that thing” or you could simply translate in your head Potential Client equals Lead. Either way you have a breakdown in communication.

Not to mention if you are using a SQL server as your persistence mechanism the table may be called “Clients”. I know this is an extreme but I don’t know how many times I have seen this in production code.

Now let’s take a quick DDD approach. You take the time to meet the product owner and you agree that the you will refer to this entity as “Potential Client”. Nirvana has been achieved why, I will tell you why! Whenever anyone uses the term “Potential Client” in UML, documents, wire frame, CODE!! Everyone knows that this is the “Potential Client”. Ubiquity has been achieved. A moment of silence if you will…

Humans in general have a talent for understanding pictures and spoken words more than we do written text. I don’t know if this based on the fact that before written languages, knowledge was passed down from generation to generation based on spoken words (more like grunting) and drawings on wall. Perhaps our brains revert to time tested state of understanding when thought becomes unclear. That explains a majority of my code. But seriously let’s try something quickly to prove my point. Whatever you do, don’t think of a pink elephant! I mean don’t let that thought enter your head. If you are somewhat normal most of you found it impossible to keep such an IMAGE out of your head. The key was the term image. When we recall objects or ideas we tend to symbolize them in our brains with images. When we thought of the elephant we saw an animal with a long nose weighs 2 tons and has big floppy ears. I gave you the value of pink to contrast it even more than you normal train of thought. You didn’t recall the actual word letter for letter “P” “I” “N” “K” “E” “L” “E” “P” “H” “A” “N” “T”. If you did, what time is Judge Wapner coming on?

This is only the tip of the iceberg concerning the ubiquitous language and this post is a lot longer than I had intended it to be. More information will be elucidated on ubiquitous language in the next post on “Entities” and that’s when we really start to have some fun.

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Joe Ocampo

My personal philosophy is simple: "Have a good strategy that sets the environment for success through the enablement of the whole. Be agile but with a mind towards pragmatism. Delegate to the best qualified individuals, but don’t be afraid to involve yourself in all parts of a job. Treat everyone with respect, humility, and with a genuine pursuit towards excellence." Respected business and technical leader with expertise in directing organization towards effective results driven outcomes. Proven ability to perform and communicate from both technical and business perspectives. Strong technical and business acumen developed through experience, education and training. Provides the ability to utilize technology, harness business intelligence and execute strategically by optimizing systems, tools and process. Passionate about building people, companies and software by containing cost, maximizing operational throughput and capitalize on revenue. Looks to leverage the strengths of individuals and grow the organization to their maximum potential by harnessing the power of their collective whole and deliver results. Co-Founder of LosTechies.com
This entry was posted in Domain Driven Design (DDD). Bookmark the permalink. Follow any comments here with the RSS feed for this post.

9 Responses to A Discussion on Domain Driven Design

  1. Franck says:

    Very interesting post that should remind us that being agile should NOT force us to forget the fact that we can model before coding ;o)

  2. Ian Spence says:

    Great article, complements the book very well. Have also read your Entities post. Looking forward to seeing more posts from you on DDD.

    Although Eric Evans makes reference to Agile, I don’t think it is a strong dependency. This style of domain modeling could still be carried out in some other development methodology.

  3. Colin Jack says:

    Really good post, I agree completely with your analysis as to how DDD fits in with TDD.

  4. Ace21 says:

    What is the difference between domain-driven design and model-driven design?

  5. Tony Burkson says:

    Join us at this 1-day, 1-track event and hear from thought leaders in software design, Domain Driven Design, strategic design and domain modeling…

    Expect to get the latest DDD lessons directly from the source – Eric Evans, Gojko Adzic, Alberto Brandolini, Phil Wills and more!

    Book before 24th May and save 30% off the regular price!

  6. Tony Burkson says:

    Join us at this 1-day, 1-track event and hear from thought leaders in software design, Domain Driven Design, strategic design and domain modeling…

    Expect to get the latest DDD lessons directly from the source – Eric Evans, Gojko Adzic, Alberto Brandolini, Phil Wills and more!

    Book before 24th May and save 30% off the regular price!

  7. jillianelu says:

    business events referred melts production years

  8. davetiye says:

    güzel davetiye sözleri ve davetiye metinleri

  9. davetiye says:

    güzel davetiye sözleri ve davetiye metinleri