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>




Ignoring the Mommy Wars. Part 1
Rebecca Mark-Jusbasche is superwoman. A multimillionaire former executive, she was named one of Fortune magazine’s 50 Most Powerful Women in Business. She also raised twin boys while building her career, taking them as toddlers to Harvard Business School with her, then bringing them along on the corporate jet when she could. Granted, not everything went [..]

Hare of Howden
In Howdentown as I have heard ‘em tell Once there was a white hare, she used to there to dwell She’s been hunted by the greyhounds and the beagle-dogs did fare And there’s not a one amongst’em could keep up with that white hare She’s faster than the black, and she’s bonnier than the brown And there’s not a dog [..]

Online Pharmacy For Pain Relief Treatment
As a person gets older, having to put up with arthritis pain is one of the worst things to deal with. The elderly are not the only ones affected by arthritis pain; younger people can suffer from it as well. In this case a person would spend most of their life experiencing the pain of [..]

Muscle Relaxers Zanaflex without prescription. Pacient info.
If your doctor has prescribed the muscle relaxant Zanaflex (Tizanidine Hydrochloride) for you, and you are uncertain about what it is exactly or how you should take it, or if you merely wish to learn something about Zanaflex medication, this information may be helpful for you. You can purchase Zanaflex (Tizanidine Hydrochloride) in either tablet [..]


All News