问题描述
我一直在学习PHP MVC模式,这很酷.几乎完成了应用程序,我可以看到无需良好设计就可以制作代码多么混乱. 现在可以将MCV应用于C ++应用程序吗?如果可能的话,插件管理器/插件在哪里?在模型或控制器中? 谢谢!
编辑:
我的意思是用GUI工具包C ++,例如qt/wxwidgets/gtk+ 另外,请帮助我如何在C ++中实施.我已经学会了如何在PHP中进行操作,但是您知道两种语言有所不同!
edit2
http://forums.wxwidgets.org/viewtopic.php = 1&t = 30983
推荐答案
您如何在C ++
中实际实现它
-
让负责渲染的课程对应用程序详细信息一无所知.称他们为" view"类以使这一点清楚
-
使您的域对象对可视化或用户交互一无所知.您不需要称它们为模型,但是您可以
-
创建一组负责运行控制器的角色的类:如果可能的话,以某种方式通过依赖性注入查看和模型类.示例: cppinject .无论如何,控制器类都可以了解模型和视图类,因此重要的部分是:视图和模型对象之间的所有耦合都隔离到控制器.
-
另外,这意味着,所有命令式编程也应限制在控制器类别上:视图和模型应为声明性式式.这意味着,他们应该提供与其角色相关的服务,但要避免直接与其他物体进行副作用
-
您需要在控制器和其他带有事件式系统的组件之间实现通信,尽管这种系统绝对有帮助,但肯定不是必需的
-
惊喜!上面的任何语言或框架都适用于任何语言或框架,除了某种程度上已经以某种方式迫使MVC从一开始就迫使您的喉咙,即:Ruby on Rails
其他推荐答案
MVC是一种设计模式而不是语言特定的构造,因此,您也可以将其应用于C ++应用程序.
MVC可以并且应该以任何语言应用,以便您的用户界面与后端松散结合,并且可以更改彼此的最小影响.
MVC模式将对象的干净分离为:
- 模型用于维护数据,
- 视图用于显示全部或一部分数据的视图,
- 控制器用于处理影响模型或视图的事件.
其他推荐答案
是的,可以在C ++中应用MVC.例如,MFC框架使用文档/视图体系结构本质上是MVC.
设计模式不是库或类.这是一种模式.因此,您没有C ++的通用MVC库.
问题描述
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!
EDIT:
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
推荐答案
how do you actually implement it in C++
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
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
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 is a design pattern not a language specific construct, So yes you can apply it to C++ app as well.
MVC can and should be applied in any language so your User Interface is loosely coupled with the backend & either can be changed with minimum impact on each other.
The MVC pattern provides a clean separation of objects into:
- Models for maintaining data,
- Views for displaying all or a portion of the data, and
- Controllers for handling events that affect the model or view(s).
其他推荐答案
Yes, MVC can be applied in C++. For example, the MFC framework uses Document/View architecture which is essentially an MVC.
A design pattern isn't a library or class. It's a pattern. So you don't have a generic MVC library for C++.