Angel \”Java\” Lopez on Blog

September 12, 2008

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

11 Comments »

  1. 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

    Comment by Vijay Patel — September 12, 2008 @ 12:07 pm

  2. 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.

    Comment by moffdub — September 24, 2008 @ 10:57 pm

  3. Great post.

    Comment by Max — September 30, 2008 @ 8:46 pm

  4. 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

    Comment by Dan Haywood — January 10, 2009 @ 10:54 am

  5. The only potential advantage about working on the west coast, is that as an animator you have more options in terms of employment. ,

    Comment by His_wife57 — October 22, 2009 @ 9:16 pm

  6. I’m really enjoying the design and layout of your website.
    It’s a very easy on the eyes which makes it much more enjoyable
    for me to come here and visit more often. Did you hire out a developer to create your
    theme? Excellent work!

    Comment by http://chillplaya.eu/member.php?action=profile&uid=7125 — December 21, 2013 @ 1:50 am

  7. 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.

    Comment by binary options trading strategy — January 5, 2014 @ 3:39 am

  8. Take a look at the article http://www.pinfaq.com/1478/domain-driven-design-architecture-layer-design-operation which explains the layer design of DDD application. Hope it gives clear picture.

    Comment by Vivek — July 15, 2014 @ 12:25 am

  9. Different allocation schemes for radio resource (RR) management have been defined inn order to multiplex several MSs on the
    sasme physical channel. Wylder is a part time freelancer
    and amateur author. Your ptactice hhas tugh decisions to make whenn allowing your staff to handle patients.

    Comment by https://itmmobileapps.zendesk.com/entries/35012955-Immediate-Systems-For-Webrtc-In-The-USA — July 18, 2014 @ 11:41 pm

  10. 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!

    Comment by mechanical — October 23, 2014 @ 10:32 am

  11. 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.

    Comment by Informaz — August 24, 2015 @ 1:06 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: