开发者

In MVP (or any architecture), where does data transforming take place?

I have an MVP application, which has the following layers:

  • Presentation
  • Service
  • Business
  • Data

Between the presentation and service layers I use DTO's.

Let's say I get data from the database using L2S or EF. I get a dataype that could be an int or datetime etc.开发者_JAVA技巧 But the presentation layer needs it as a string or in a certain format. Where exactly does this take place?

Does the service do this? The DTO? The presenter? Some other place?


There are two types of transformation.

There's transforming a database field into a useful data model object (probably in your business layer) and there's transforming your model data into some kind of presentational object.

The former would be converting a BIT field in the database to a Boolean in your model.

The latter would be converting a DateTime to a visible string in your presentation.

These two transformations happen at the data extraction point and at the presentational rendering point.


But the presentation layer needs it as a string or in a certain format.

If the presentation layer (UI) requires it in a certain format (otherwise it can't inter-operate) then you have no option but to convert it - yet the conversion is most likely UI specific; in such cases the best option (for flexibility / separation of concerns) would be to build a UI specific adapter / proxy / facade (which does the conversion) that sat between the UI and where ever it gets its data.

This would work in scenarios where you have control over the entire system - except the UI.

A possible subtlety I read into your question is not that the UI requires it in a specific format but that it, shall we say "strongly prefers" it in a specific format; in which case you would build the adapter / proxy into the UI.

This would apply in scenarios where you control the UI but not the rest of the app. It doesn't sound like that's the case in your scenario - but worth mentioning.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜