开发者

using MVC in non web based app

开发者 https://www.devze.com 2023-02-08 03:32 出处:网络
I know that MVC design pattern is popular, mainly in the web based apps. I\'m curios to know how the MVC design pattern can be used in de开发者_开发知识库sktop applications environment.

I know that MVC design pattern is popular, mainly in the web based apps. I'm curios to know how the MVC design pattern can be used in de开发者_开发知识库sktop applications environment.

To be more specific, let's consider the VLC media player. Can the VLC be written accordingly to MVC pattern? Who is M, V, C and who is the "dispatcher"?

Maybe the VLC isn't the perfect example, but I think it is a popular application. VLC isn't only about playing a video it has built in codecs and also some video effects adjustment support.


I think MVC doesn't get mentioned with desktop applications so much because a desktop app already follows the MVC approach. You have a GUI (your view) which has a series of interactivity points that cause events (call a controller).

Sticking with a simpler app:winamp.

Controller-Initiation Points:

  • Menu options
  • Buttons

View Points:

  • Total GUI
  • Track information panel (artist/track etc)
  • Visualization panel (graphic eq)

You certainly can use the MVC pattern for a desktop app - and will realize the same benefits as a web-app.


I've used the MVC pattern for non-web applications before. It's actually a really good approach for implementing a variety of interfaces to one application. In my experience:

The Models are pretty obvious; they don't change. In the VLC example, they could be things like input files.

The Controllers don't really have to change much either (if they're well written). Controllers should be basically agnostic to the interface-type (web, cli, etc.). A given controller action should be thought of as saying, "here is where you __ with the data."

The Views are where significant refactoring comes in. Simply re-create the views with input/output appropriate to the medium (e.g. windowing instructions, rather than HTML resources).

Finally, the "dispatching" in this case would be done by the application executable which would effectively be communicating messages -- translating user input (and other input) into calls to the controller (just as in a web app).

Check out Wikipedia's article on the MVC pattern for more info.

0

精彩评论

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

关注公众号