MVC 方法与 C++

MVC approach with C++(MVC 方法与 C++)

本文介绍了MVC 方法与 C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习 PHP MVC 模式,它非常酷.几乎完成了应用程序,我可以看到如果没有良好的设计,您可以制作出多么混乱的代码.现在可以将 MCV 应用于 C++ 应用程序吗?如果可能的话,插件管理器/插件会去哪里?在模型还是控制器中?谢谢!

I have been learning PHP MVC pattern and it is pretty cool. have almost finished app and I can see how mess you can make a code without good design. Now can MCV be applied to C++ apps? Where does Plugin manager/Plugins go if that is even possible?In model or controller? Thanks!

我的意思是带有像 QT/Wxwidgets/GTK+ 这样的 GUI 工具包的 C++另外请帮助我如何在 C++ 中实现.我已经学会了如何在 PHP 中做到这一点,但正如您所知,这两种语言在某种程度上是不同的!

I mean C++ with GUI toolkit like QT/Wxwidgets/GTK+ Also Please help me on how to implement in C++. I have learned how to do it in PHP but as you know the two languages are somehow different!

EDIT2

http://forums.wxwidgets.org/viewtopic.php?f=1&t=30983

推荐答案

你如何在 C++ 中实际实现它

how do you actually implement it in C++

  • 让负责渲染的类对应用程序的细节一无所知.将它们称为SomethingView 类以明确这一点

    • make classes in charge of rendering know nothing about application details. Call them SomethingView classes to make this point clear

      让你的领域对象对可视化或用户交互一无所知.你不需要称它们为模型,但你可以

      make your domain objects not know anything about visualization or user interaction. You don't need to call them Model, but you could

      创建一组负责运行控制器角色的类:如果可能的话,通过依赖注入以某种方式将依赖连接到视图和模型类.示例:CppInject.在任何情况下,控制器类都可以知道模型和视图类,所以重要的部分是:视图和模型对象之间的所有耦合都与控制器隔离.

      create a set of classes in charge of running the role of Controllers: wire somehow dependencies to view and model classes via dependency injection if possible. example: CppInject. In any case, controller classes can know both about model and view classes, so the important part is this: all the coupling between view and model objects is isolated to the controllers.

      此外,这意味着所有命令式编程也应该局限于控制器类:视图和模型应该是声明式的.这意味着,他们应该提供与其角色相关的服务,但避免与其他对象直接交互作为副作用

      Also, this implies, that all imperative-style programming should be confined to the controller classes as well: view and model should be declarative-style. That means, they should offer services related to its role, but avoid direct interaction with other objects as side-effects

      你不需要用事件式系统来实现控制器和其他组件之间的通信,虽然这样的系统肯定有帮助,但肯定不是必需的

      It is not true you need to implement communication between controllers and the other components with event-style system, although such system is definitely helpful, but certainly not required

      惊喜! 以上适用于任何语言或框架,当然除了那些从一开始就以某种方式迫使 MVC 扼杀你的语言,即:ruby on rails

      surprise! the above applies to any language or framework, except of course languages that somehow already force MVC down your throat from the start, i.e: ruby on rails

      这篇关于MVC 方法与 C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:MVC 方法与 C++

基础教程推荐