Layered architecture in Domain-Driven Design

This time, let explore the concepts of a layered architecture, as proposed by Eric Evans in its classic book Domain-Driven Design, Tackling Complexity in the Heart of Software. In the chapter four of the book, Evans presents this diagram:

 

Evans writes:

For a shipping application to support the simple user act of selecting a cargo’s destination from a list of cities, there must be program code that (1) draws a widget on the screen, (2) queries the database for all the possible cities, (3) interprets the user’s input and validates it, (4) associates the selected city with the cargo, and (5) commits the change to the database. All of this code is part of the same program, but only a little of it is related to the business of shipping.

He proposes that the domain model resides in a layer, the Domain Layer. In this way, the domain model is protected from technicalities as concrete persistence implementation, and presentation duties. I like to say that the domain is as an organism, that receives stimula, actions from the outside, and reacts to such commands. The domain should run without detailed knowledge of the rest of the application. Serialization between physical tiers, presentation details and database access, should be clearly separated from the domain implementation.

The layers could be described as:

UI (User Interface): the easiest to understand, this layer is the responsible of displaying information to the user, and accept new data. It could be implemented for web, desktop, or any presentation technology, present or future. For example, it could be a voice application, that interacts with the user via a phone. The acid test for our design is that a radical change in user interface should have minimal (or controled, at least) impact in the rest of the system.

Application Layer: it’s in charge of coordinating the actions to be performed on the domain. There are no business rules or domain knowledge here. No business state resides in this layer. It delegates all domain actions to the domain. It could coordinate many actions (possibly in many domains). It could prepare the infrastructure to be ready to work with the domain for an specific action (for example, preparing transaction scopes).

Domain Layer: In this layer resides the heart of software, according to Evans. Business rules and logic lives inside this layer. Business entity state and behavior is defined and used here. Communication with other systems, persistence details, are forwarded to the infrastruture layer. Evans discuss the patterns he uses in this layer, as Entities, Value Objects, Services, Repositories and Factories. We would explore the patterns and implementations in future posts.

Infrastructure Layer: God and devil are in the details, and in the infrastructure layer. Its main responsability is the persistence of the business state, most frequently, using a relational database.

My idea is to take an example (possibly a domain from Jimmy Nilsson), and develop it using these ideas, showing concrete code in Java and .NET. At some point, I will discuss about code generation from an abstract model, but it will not be the focus of these posts.

Sources:

Domain-Driven Design, Tackling Complexity in the Heart of Software, by Eric Evans.
Applying Domain-Driven Design and Patterns: With Examples in C# and .NET, by Jimmy Nilsson
.NET Domain-Driven Design with C#, Problem, Design, Solution, by Tim McCarthy. (There is a section in Tim’s blog dedicated to this book).

You can download freely

Domain-Driven Design Quickly

from InfoQ.

Angel “Java” Lopez
http://www.ajlopez.com/en

19 thoughts on “Layered architecture in Domain-Driven Design

  1. Vijay Patel

    Nice post.

    I do think it’s important to emphasise the “Domain” in Domain Driven Design. Developers need to understand the domain model before they start creating templates/xml files – and that can be quite tricky itself (depending on the complexity of the business).

    If anyone is interested in rapid domain modelling, we offer a tool to do just that. You can find it at:
    http://www.evolving-software.co.uk

    The best of luck with your project.
    Vijay Patel

    Reply
  2. moffdub

    I think you’ll have fun with your DDD project. Don’t be afraid of merciless refactoring either. You’d be surprised at how the simplest of domains ends up being much more interesting than you initially thought.

    Personally, there is a strange satisfaction from reading your code and realizing it reads like an English sentence. DDD aids greatly in this quest.

    Reply
  3. Dan Haywood

    Could you explain in a bit more depth what the responsibilities of the application layer are? Transaction management is an obvious one, and DTO assembly is perhaps another for distributed/distributable architectures. I’ve also heard the app layer being part of the “solution space”, and the domain layer part of the “problem space”, but I’m not sure if I believe that or if its helpful.

    Anything else? Other comments?
    Dan

    Reply
  4. binary options trading strategy

    Incorporate the aforementioned steps in your strategy together with
    discipline, persistence and determination and
    you will have taken the first steps to achieving trading success.
    These are just some from the basics of binary
    options. This ensures that the workplace is extremely laidback and casual.

    Reply
  5. mechanical

    I used to be recommended this website by means of my cousin. I’m now not certain whether or not this submit is written by way of him as no one else recognize such distinctive about my problem.
    You’re wonderful! Thanks!

    Reply
  6. Informaz

    pene piu lungo

    The next step is in addition applied while covering. Acrylic absolutely tell this related materials in accordance with the item surely tell the proper glow and so perhaps in material without difficulty pomieściłyby some more automobiles. The correct colour you wish to paint shade from your quick color. A comparable whenever he or she propagate a solid picture with the most recent tendencies with design. Traces associated with auto parking spaces essential yet it should be dried up. We’ve got already applied coloring and also gypsum panels. Using a specific manufacturer. Much better would be the restoration in the doorway leaf and ease and comfort. Dry out. And it’s also not big. The actual limit no matter what additional aspects, tangible and also current collection of paints in order to drill as well as family and friends meet progressively extended, boring, among others is going to be upon anti-corrosive; undercoats, yet really tough. in which for you to some of the most current styles layout. Many years having a firm spatula to be able to scrape the actual threshold to begin art work rooftops. Cornices. In order that it called for one more. complete wall structure paneling. Scandinavian spruce and secure their moist this specific extremely properly painted line. It is big. Producing a 1000 colors, as well as enable you to produce your own, for starters of which less.

    Reply
  7. gorden untuk rumah sakit

    Grеɑt blog here! Additionally your website гather a ⅼot up faѕt!
    Ԝhat web host are yօu the use оf? Can I am ցetting
    your associate hyperlink in yoսr host? I wish mү site loaded uρ as
    fаst as yоurs lol

    Reply
  8. jual kitchen set jadi

    Thanks fⲟr everү other informative web site. Ꮃhere elsе
    ϲould I am ցetting that type of info writtеn іn such a perfect wɑy?
    І hаve a mission that I’m simply noԝ ѡorking օn, ɑnd I
    haᴠe been on the glance out for such іnformation.

    Reply
  9. Preguntón Cojonero Cabrón

    “My idea is to take an example (possibly a domain from Jimmy Nilsson), and develop it using these ideas, showing concrete code in Java and .NET.”

    Code ?

    Reply

Leave a comment