问题描述
限时送ChatGPT账号..我正在开发一些新软件,并试图使其尽可能模块化.我已经编码了一段时间......但我缺乏一些我在学习过程中正在学习的关键原则.
I'm working on some new software, and I'm trying to make it as modular as possible. I have been coding for a while..but I lack some key principles which I am learning as I go along.
为了使我当前的项目模块化,我使用了模型-视图-控制器架构.在设计我的应用程序时,我发现了一些我不确定的事情.所以我来找你...
In trying to make my current project modular, I am using the model-view-controller architecture. In designing my application, I have found certain things I am unsure of. So I come to you...
我会给你一些可能有用的信息:
I'll give you some information which may be useful:
我正在 Qt 中开发这个应用程序.这是一个桌面应用程序.单用户,所以不是很复杂我的问题是:
在实现各种模块(模型、视图等)和所有与它们关联的类,我应该初始化模块中的模块?我应该在一个控制器",或者我应该在主要"中创建所有内容,然后简单地将模块作为引用传递?
When implementing the various modules(models, views etc..) and all of the classes associated with them, should I be initializing modules within modules? Should I create a 'model' instance within a 'controller', or should I create everything in 'MAIN' and simply pass the modules as references?
我的策略是将我的应用程序分成许多 MVC 包.每个人都会遵循的基本原则:模型获取数据,视图显示它,控制器负责处理之间的所有交互模型视图,并执行所有必需的逻辑.这是正确的吗?
My strategy is to separate my application into many MVC bundles. Each one will follow the basic principles: model gets the data, view displays it, and controller takes care of all interactions between model-view, and performs all required logic. Is this correct?
感谢您的帮助.
谢谢.
推荐答案
我应该在控制器"中创建一个模型"实例,还是应该在主"中创建所有内容并简单地将模块作为引用传递?
Should I create a 'model' instance within a 'controller', or should I create everything in 'MAIN' and simply pass the modules as references?
将模块作为引用传递.我不知道 Qt 是否有包内包的概念,但在 Java 中,我有单独的模型包和视图包.
Pass the modules as references. I don't know if Qt has the concept of packages within a bundle, but in Java, I have separate packages for the model and the view.
我的策略是将我的应用程序分成许多 MVC 包.每个人都会遵循基本原则:模型获取数据,视图显示数据,控制器负责模型-视图之间的所有交互,并执行所有必需的逻辑.这是正确的吗?
My strategy is to separate my application into many MVC bundles. Each one will follow the basic principles: model gets the data, view displays it, and controller takes care of all interactions between model-view, and performs all required logic. Is this correct?
是的,这是正确的 MVC 原则.
Yes, that's correct MVC principles.
有时在更复杂的应用程序中,您的应用程序视图可能由 GUI(视图)和 GUI 的模型(模型)组成.在这种情况下,应用程序模型(可能是数据库访问模型)与 GUI 模型交互.GUI 和应用程序的控制器均由用户操作驱动.
Sometimes in a more complicated application, your application view might consist of the GUI (a view) and a model of the GUI (a model). In this case, the application model, which is probably a database access model, interacts with the GUI model. The controller for both the GUI and the application is driven by the actions of the user.
这篇关于MVC 编程实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论