Sorting out POCO, Repository Pattern, Unit of Work, and ORM
I'm reading a crapload on all开发者_如何学C these subjects:
POCO
Repository Pattern Unit of work Using an ORM mapperok I see the basic definitions of each in books, etc. but I can't visualize this all together. Meaning an example structure (DL, BL, PL).
So what, you have your DL objects that contain your CRUD methods, then your BL objects which are "mapped" using an ORM back to your DL objects? What about DTOs...they're your DL objects right? I'm confused.
Can anyone really explain all this together or send me example code? I'm just trying to put this together. I am determining whether to go LINQ to SQL or EF 4 (not sure about NHibrernate yet).
Just not getting the concepts as in physical layers and code layers here and what each type of object contains (just properties for DTOs, and CRUDs for your core DL classes that match the table fields???).
I just need some guidance here. I'm reading Fowler's books and starting to read Evans but just not all there yet.
I will assume that DL - Domain Layer, BL - Business Layes and PL - Persistence Layer.
If you need a simple CRUD application you should not use DDD principles. Use DDD if you have a complex domain model to implement.
In DDD you will have DL and BL combined with ALL the logic inside your domain objects/services. Otherwise you will build an Anemic Domain Model. Avoid setters on properties and change your objects only via method calls like ChangeAddress instead of obj.Address = newAddress or Activate instead of obj.Active = true.
Data-Transfer-Objects should be used only for communication with external services/UI. Inside your domain you will use Domain Objects only.
I suggest to use task-based UI.
What persistence technology to use in Persistence Layer depends on your requirements. Before you will choose SQL RDBMS take a look at Object-relational impedance mismatch wikipedia page.
For the implementation samples please check related questions:
- Are there any open source projects using DDD (Domain Driven Design)?
- Good Domain Driven Design samples
- .NET DDD Example
精彩评论