基于WTL的应用程序中的模型-视图-控制器模式 [英] Model-View-Controller pattern in WTL-based apps

查看:113
本文介绍了基于WTL的应用程序中的模型-视图-控制器模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关Model-View-Controller模式的信息,我计划将其用于基于WTL的项目.例如,我想编写一个计算器应用程序.

首先,我编写执行实际计算的CCalculator类.这是用MVC表示的模型.

然后,我创建一个对话框并编写CCalculatorDlg类(从WTL的CDialogImpl模板类派生)来处理对话框事件.就MVC而言,这是什么?视图还是视图控制器?如果这只是一个视图,那么我是否应该编写另一个类,例如CCalculatorController,作为CCalculatorDlg和CCalculator之间的中介?如何正确地将MVC模式应用于WTL?

I''ve read about Model-View-Controller pattern, and I plan to use it for my WTL-based project. For example, I would like to write a calculator application.

First of all, I write CCalculator class that performs actual calculations. This is the model in terms of MVC.

Then I create a dialog and write CCalculatorDlg class (derived from WTL''s CDialogImpl<> template class) to handle dialog events. What is this in terms of MVC? View or view-controller? If this is just a view, than should I write another class, say CCalculatorController, as an intermediary between CCalculatorDlg and CCalculator? How to apply MVC pattern to WTL correctly?

推荐答案

问题的答案问题是如何正确地应用MVC模式?视图是什么,控制器是什么? ?"是MVC的一部分.继续阅读.它需要一些分析和架构方面的经验.

该模型是用数据表示的计算模型:操作数和计算结果.我认为它不应包含表示数字数据的任何字符串,而应仅是数字.在一个或多或少先进的计算器中,是否应该类似于表达式树.

视图应该是带有控件的窗口.

窗口的事件应在Controller中实现.这个想法是:不应在与UI相关的处理中转换事件. Controller应该消耗所有事件,以更新模型的状态.然后,Controller使用整个更新的模型将其映射到View的状态.

现在,计算器的功能是什么?我会说这是一个带有按钮(1、2、3,+,-等)的计算器,这将浪费时间.谁需要它?只是为了模仿标准的历史计算器.真正的东西应该与文本输入一起使用.

我知道您只需要锻炼即可.否则,为计算器创建Windows应用程序将浪费时间.为什么?因为实用的计算器就像我的东西:

http://www.sakryukov.org/freeware/calculator/ [
The answer to the questions "The question is how to apply MVC pattern correctly? What is the view and what is controller?" is a part of MVC. Keep reading. It need some experience in analysis and architecture.

The Model is the calculation model represented in data: operands and result of calculation. I think it should not contain any strings representing numeric data, should be numeric-only. In a more or less advanced calculator if should be something like expression tree.

The View should be the window with controls.

The events of the window should be implemented in Controller. The idea is: the events should not be translated in the UI-related processing. All events should be consumed by Controller to update the state of the model. Then the whole updated model is used by Controller to map it on the states of the View.

Now, what is the functionality of the calculator? I would say in this is a calculator with buttons (1, 2, 3, +, -, etc.) it would be a waste of time. Who needs it? Just to mimic standard historical calculator. The real thing should work with text input.

I would understand that you need it just for exercise. Otherwise, making a Windows application for a calculator would be a waste of time. Why? Because a practical calculator is something like mine:

http://www.sakryukov.org/freeware/calculator/[^].

—SA


这篇关于基于WTL的应用程序中的模型-视图-控制器模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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