Which pattern to create domain objects from web request objects [duplicate]

I’m a little confuse how to create domain objects right. In all/most web application we have simple objects created from POST request. We need to create domain objects that we will use in deeper layers. How we should do this? What kind of pattern should be used? It is very general question but I’ve considered many patterns (factory, builder, mappers) and still have no good idea.



Your domain objects design depends on your, well, domain.

You haven’t given one so I’ll just say the point of domain objects is to create a layer in your architecture where details, like web, database, user interface, are unknown. If your domain object knows you display in a web page it’s not a domain object.

Domain objects ignore how the system works. They focus on what the system should do. If your application makes sandwiches your domain objects should know about ingredients, amounts, grilling, toasting. They shouldn’t know about knives, bread boards, jars of peanut butter, measuring cups, grills, or toasters. Those details should be abstracted away. A domain is what’s on the recipe card. It’s not the card.

Just write the code that works and does what you need. Don’t worry about what to call that code.


You are instanciating your domain objects from data. The repository pattern should work well.

However, given that its not a database the naming convention is to call it a service.

     DomainObject Get(string id);

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *