MVC编程实践 [英] MVC programming practices

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

问题描述

我正在开发一些新软件,并且正在尝试使其尽可能模块化.我已经编码了一段时间了.但是我缺少一些关键的原理,这些原理在我学习的过程中会不断学习.

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.

在尝试使我当前的项目模块化时,我正在使用model-view-controller体系结构.在设计应用程序时,我发现了某些不确定的东西.所以我来找你...

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中开发此应用程序.
  • 这是一个桌面应用程序.
  • 单用户,所以不是很复杂

我的问题是:

  1. 在实现各种模块(模型,视图等)以及所有与它们相关的类中,我应该初始化吗模块内的模块?我应该在控制器",还是我应该在主"中创建所有内容,并简单地通过模块作为引用?

  1. 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?

感谢您的所有帮助.

谢谢.

推荐答案

我应该在控制器"中创建模型"实例,还是在"MAIN"中创建所有内容,然后简单地将模块作为引用传递?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆