开发者

MVC : Should the Model layer only contain DAO and DAOHelpers?

what you think should be present in the Model Layer ? Only DAO and DAO Helpers ? what else could be present ? Logger ? what ?

I am designing m开发者_Python百科y first app and yesterday I had a Model helper class that could be used in, but I was not sure where I should put it.

It was a Data Fetcher and formatter class, for some types of things of my app.

Cheers.


Only the model classes (DAO) including interfaces and common base classes should go into the model layer.

Logger is another functionality and as it is used by other layers/tier too, I'd put it in some sort of "framework" layer, a layer that collects all those helper classes that can't be assigned to one specific layer.


Wikipedia tells us, that the MVC pattern "isolates 'domain logic' (the application logic for the user) from the user interface (input and presentation)". In that case, for a pure MVC implementation with three layers only, all domain logic (DAOs, business logic, even persistence logic) would have to go into the model layer.

But for me, that's a reason to not limit the archetecture to those three layers and to add persistence layer, framework layer and business service layer as needed. The MVC layers are some sort of "sub system" inside the whole system of architectual layers.


Model:
The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.

So if we follow this classic statement then of-course all Data Access Objects and interfaces (Facade) should only be part of the Model layer.


In the model should be ALL the data, as it should be presented in the view. View is ONLY a presentation layers and shouldn' do any logic (yes I know, I do some foreach loops as well in my view).

So, my conclusion is that in a model, you translate your data (this can be DAO) do data you can output as is in your view. For me this can also be new objects that live only inside the model.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜