Setting the scene - Layered Architecture

14 02 2008

Domain Driven Design is all about capturing the business logic into application code, no matter how complex it is. But code is not about business logic alone, there needs to be some code to take care of several other aspects like interfacing, data retrieval and persistence, communication, logging, security and much more…

Layered ArchitectureTo ensure that your business logic implementation becomes as maintainable as possible, it should not be influenced by any of the other code. To achieve this, you should separate it from the other aspects using a Layered Architecture.

An example of such a layered application can be found in the picture on the right. Note that layering is only a logical separation of your application and as such it is represented in the solution using solution folders which contain all the assemblies that belong to one logical layer.

The recommended approach for a layered solution is to start of with 4 different layers:

  • Domain layer : Central to the solution should be the domain layer which contains all the business logic for the problem domain at hand. Ensure that this layer is not influenced by any of the other layers.
  • Resource layer : The resource layer supports the application by ensuring that the domain layer gets constructed from any resources at hand, this could be done from a local persistence store like a database or an xml file, or it could be reconstructed from a remote location like a remote service.
  • Interface layer : The interface layer takes care of displaying information from the domain model in the form requested by the consumer. This could be a windows form, a web site, a web service or a wcf data contract depending on the nature of the consumer which could be a human or another service.
  • Application layer : The application layer has the responsibility to coordinate the execution of tasks for the consumer. When the consumer is another service, this layer is rather redundant. But when a human is involved, a lot of state needs to be maintained so that the user gets presented all the reference data she can use to determine her choices before calling into the domain layer.

Special note: When you read the Domain Driven Design book, you will notice that there is no such thing as a resource layer in there. Instead it’s called the infrastructure layer which contains both resource access as other kinds of infrastructure like logging etc… But my experience has learned that you want your infrastructure code out of the way as much as possible, preferably all infrastructure should be invisible in your application using techniques like aspect oriented programming, dependency injection and such. Therefore I recommend to separate all infrastructure code outside your solution into a framework, but leave the resource access in.

Next time we will start the discussion on domain modelling and how to ensure it stays maintainable even when it becomes pretty complex.

See you next time,
Yves Goeleven


Actions

Information

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Circuit Training for a Change of Pace


Try circuit training to get or keep you fit when you’re short of workout time. Circuit training consists of going quickly from one exercise to another for an extended period of time, say 20 minutes. It is promoted as giving both strength and aerobic training in the same workout. It does that, but you compromise both. [..]


Decreasing the Incidence of Work-Related Back Injury


Many of us spend many a long hour each day sitting at a desk and working on a computer. Do you sit in the right position? Think about how you sit. It’s common that the longer you sit, the more you will find that you are slumping in the chair. This causes the bottom of [..]


Leave Men Alone


Some men should not be left alone. Not because we don’t trust them. Not because they can’t find anything when you are gone. There is another reason. If you do, what happens is this: bad things happen. At least, this is what my wonderful husband says when I go off on a plane somewhere. He’s not the [..]


Does a Positive Outlook Reduce Stroke Risk?


Are happy people healthier because they participate in wholesome activities or does depression somehow contribute biochemically to stroke? This study doesn’t begin to answer any of these questions, but it is something to think about. It’s difficult to say that a bad attitude can give you a stroke but one study of almost 2,500 persons 65 [..]


Taking Care of Your Teeth. Dangerous Food


A lot of people don’t think of the harm that they are doing to their teeth when they gobble down chocolate, candy, or chips. It might shock you to learn what food is terrible for your teeth and what food is even more terrible for your tooth. It is a problem when tooth decay happens [..]


All News