Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have spent the past several days learning about domain driven design and attempting to apply it to a current project. I decomposed the problem domain into the canonical logical components: domain, infrastrucutre, and presentation. Having completed a first pass, I stepped back and realized that the architecture I created resulted in virtually all of the business logic being contained in the application services, which is the tell-tale sign of the anemic domain model code smell. After further consideration, domain driven design may not be the correct fit for my application, and even if it is, given the small number of business logic rules in my application, the layering overhead may not be worth it. Since I have only written UML and psuedo code I haven't invested too much time and effort, but I would like to leverage what I can if it's possible.

My architecture consists of 4 physical components:

  1. The "domain" project: abstractions and CRUD methods for the data type I use
  2. The "infrastucture" project: the logical representation and methods to be performed on the data
  3. The "presentation" project: the user interface (WinForms or WPF)
  4. The "services" project: coordiates the domain and infrastucture objects according to business rules

If I were to use the components as designed in a multitiered architecture, my presentation layer would only hold references to 3 or 4 services to handle all application functionality. Is this a valid approach?

share|improve this question

migrated from stackoverflow.com Oct 11 '12 at 17:31

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 4 down vote accepted

I think that you are on the right track but it might be easier to understand possible different nomenclature to get a better understanding about the role that each of the layers will play in the architecture.

The Martin Fowler article that you linked where he coined the term, Anemic Data Model was his criticism at the time for transactional based architecture and the trend to push Behavior out of data objects entirely. Being a staunch believer in OOP programming and design it is a valid criticism, as he worries about the sophistication of software devolving back to the days of structs and procedural programming. Personally I feel he is rather alarmist and this will not be a problem if strict architectural adherence to layerd and tiered software design is followed in a stateless and transactional way.

  1. Domain layer consists of data objects that have the knowledge and ability to persist themselves to database or file

  2. Infrastructure layer This could also be known as your Data Access Layer. Stateless DAO classes will have the ability to fetch data objects.

  3. I propose you have a seperate Business Logic Layer. Any and all application logic, special domain logic, interactions with multiple DAO or external web services, integrating third party services to satisfy business rules and all in a stateless transactional way, are all examples of what code belongs here. Sure some of this will simply be a wrapper to a single DAO call, but the seperation of concerns and low coupling is the benefit.

  4. Presentation Layers There can be multiple presentation layers but they will typically be the arbiters of stateful communication with your users. A good example of this would be the Controller in MVC architecture. It can maintain stateful interaction, and where business logic operations are required, it should be as simple as calling the necessary transactions to retrieve the data needed or perform the necessary operation. There are different types of presentation as well, a thick client or web server will can call the business logic layer directly, or perhaps the business logic can be wrapped by web services that return the data in a useful form.

  5. Service Layers The service layer should be devoid of any application or business logic and should focus primarily on a few concerns. It should wrap Business Layer calls, translate your Domain in a common language that your clients can understand, and handle the communication medium between server and requesting client.

Knowing this and understanding the benefits of why this type of transactional architecture might be useful to you however depend entirely on the type of software that you are building. Also questions about the appropriate number of services are meaningless in this case without a complete understanding of your business and technical requirements. It is a valid approach if you wish to build large highly maintainable, scalable solutions with low coupling. If you are building a smaller application with few business concerns or objectives then perhaps it is overkill.

share|improve this answer
    
Thank you for your post. Your nomenclature definitions make sense to me and are the ones I have been using -- my recent tangent into domain driven design notwithstanding. Given my application is a local client app interfacing with the filesystem only, I do not believe a service layer is needed at all in my case. –  Noren Oct 11 '12 at 18:55
    
@Noren Yes you are probably right. A multi-tiered transactional based system without DBMS persistence would probably be overkill for your application. While it can be a lot of work though, they are highly maintainable and adaptable to volatile business requirements. –  maple_shaft Oct 12 '12 at 2:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.