我更喜欢的一种MVC的理解

这个是MVC的最大众化的理解。 但是我后来还是更喜欢最近发现的另一种解释。

Model -- Data only. Get methods, setmethods, etc. It is isolated -- it knows nothing about the View, nor theController.

 

View -- UI only. Dumb or"humble". Only shows what you tell it to, and never performs anytransformation or validation logic -- e.g., it always forwards input via anevent/callback system. It is isolated - it knows nothing about the Model, northe Controller.

 

Controller -- Sits between Model andView. Does any data transformation (business logic) that is necessary to getthe data from the Model to the View. Does most data validation on input thatcomes back from the View. It "knows" about both the View and theModel.

 

With this definition it becomes mucheasier to divvy up work between engineers. If someone is a database engineer,they probably don't know UI. But they can write the Model to great effect, andhey maybe they can stub out a crappy-and-simple View. Maybe it's simply a textdump of the data, that's fine. At least the code-level interface is in place.Then the UI developers can come and write the Controller and View. Then whenthe UX designers change what they want the UI to look like, you can eitherchange the View or write a new one. Or if you want to use different UItechnologies -- WinForms on XP, WPF on Vista, or Cocoa on MacOS, then just havedifferent View implementations for each. Things like skinning are then easilyisolated to the View pillar.

 

The other useful pattern to employ hereis an Inversion of Control (IoC) container/scope object. None of the classesparticipating in MVC need to know about the specific implementation of eachother, just the interface/contract. This makes it trivial to unit test theController with faked out View and Model implementations. The Controller justsays, "hey Create me an instance of I____View" ... and your unit testharness just happens to be providing it the Mock____View instead of the____View that is used in production.


也就是说 View <--> Controller <--> Model



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值