简体   繁体   English

多个输入输出和步骤winform应用

[英]Multiple input-ouput and steps winform application

I am developing a winform application where a set of classes and its methods calculate a geometry from 3d points. 我正在开发一个Winform应用程序,其中的一组类及其方法从3d点计算几何形状。

As there is some input from the user needed from step to step in the algorithm we have designed some buttons which represent the steps. 由于算法中的每一步都需要用户输入,因此我们设计了一些代表步骤的按钮。 The intermediate data is stored in a class (maybe we use a structure in future Versions), so as the user input is. 中间数据存储在一个类中(也许我们在将来的Versions中使用一个结构),就像用户输入一样。 As result of pushing the Buttons the intermediate data will be calculated, saved and shown to the user, so that he can edit it, affecting to the calculation in the next steps. 按下按钮后,中间数据将被计算,保存并显示给用户,以便他可以对其进行编辑,从而影响后续步骤中的计算。

The application began as an application which calculate everything in 4 steps but now we have more than 10 steps so we have divided it into 3 parts (horizontal geometry, vertical geometry and other...). 该应用程序最初是一个应用程序,它按4个步骤计算所有内容,但是现在我们有10多个步骤,因此我们将其分为3个部分(水平几何,垂直几何等)。 Now I am doing some divisions because everything is getting too complex to manage all the gui interaction in one Form so I will create user controls for the smaller parts of the form. 现在,我正在做一些划分,因为一切都变得太复杂了,无法在一个Form中管理所有gui交互,因此我将为表单的较小部分创建用户控件。

Do you have general recommendations for me? 您对我有一般性建议吗?

Should I have these data structures (input and intermediate data) in the controls I make or in the general form? 我应该在我制作的控件中还是以一般形式拥有这些数据结构(输入和中间数据)?

You should avoid mixing UI with the business logic. 您应该避免将UI与业务逻辑混合在一起。 In that way when the program grows larger it will be a lot easier to maintain. 这样,当程序变大时,维护起来会容易得多。 It will also make it much simpler to write automated unittests. 这也将使编写自动化的单元测试变得更加简单。

If there is no particular reason you are using winforms. 如果没有特殊原因,则使用Winforms。 I would recommend using Windows Presentation Foundation (WPF). 我建议使用Windows Presentation Foundation(WPF)。 Read a tutorial about the Model View ViewModel (MVVM) design pattern. 阅读有关模型视图ViewModel(MVVM)设计模式的教程。 This is a very nice way of separating the UI logic from the business logic. 这是将UI逻辑与业务逻辑分离的一种很好的方法。

It takes some effort to switch from Winforms to WPF but it is definitely worth it. 从Winforms切换到WPF需要花费一些精力,但是绝对值得。

EDIT (answer to comment) 编辑(回答评论)

Well it depends on the problem your solving. 好吧,这取决于您要解决的问题。 But generally: 但通常:

In the MVVM pattern the: 在MVVM模式中:

Model would contain all your data and algorithms in classes/methods. 模型将以类/方法包含所有数据和算法。 The ViewModel would connect all the stuff you have in your Model and control the flow of the program, it will expose properties (commands, strings, numbers collections etc...) that view can bind to. ViewModel将连接您模型中的所有内容并控制程序的流程,它将公开视图可以绑定的属性(命令,字符串,数字集合等)。 The View is simply a "skin" that makes it possible for the user to communicate with the ViewModel. 视图只是一个“皮肤”,使用户可以与ViewModel进行通信。 This is a very simple explanation of the MVVM pattern and I would recommend reading a tutorial about it. 这是对MVVM模式的非常简单的解释,我建议阅读有关它的教程。

The first time I came across this pattern it was called Model View Controller MVC, I like what AngularJS is doing by just calling it Model View Whatever MVW because there are a lot of MV* out there. 第一次遇到这种模式称为模型视图控制器MVC时,我喜欢AngularJS所做的工作,只需将其称为Model View What MVW,因为那里有很多MV *。 But WPF is specifically built for MVVM. 但是WPF是专门为MVVM构建的。

The most important thing, if your creating a program that is going to be used and maintained for many years, is to keep the code as simple as possible. 如果您要创建一个将要使用并维护多年的程序,那么最重要的是使代码尽可能简单。 Instead of writing all the functionality into the Button_Click event handler (I have seen some programs that do this), try to write a class or method for every single task (use long descriptive names), this is also called Seperation of Concerns. 与其将所有功能都写入Button_Click事件处理程序中(我已经看过一些程序可以这样做),而是尝试为每个任务(使用长描述性名称)编写一个类或方法,这也称为关注点分离。 In other words one method/class should not do more than one tasks. 换句话说,一个方法/类不应执行一项以上的任务。 The nice thing is that you end up with a "program flow controller" (ViewModel/Whatever) that just passes data from one method to the next. 令人高兴的是,您最终得到了一个“程序流控制器”(ViewModel / Whatever),该程序仅将数据从一种方法传递到另一种方法。 And just by looking at the code you go: Aha I know exactly what is going on here! 只需查看代码即可:啊哈,我确切地知道这里发生了什么! In the same way when you look at your algorithms (Model) they should do a single job and all variables should be have descriptive names. 以同样的方式,当您查看算法(模型)时,它们应该完成一项工作,并且所有变量都应具有描述性名称。 This makes it very easy for other developer to understand the code. 这使得其他开发人员很容易理解代码。

I also have very good experience with dividing my namespaces according to type. 在根据类型划分名称空间方面,我也有很好的经验。 So every time you have more than one object of some sort (DataProviders, FileReaders, etc...) create a namespace/subnamespace for them and put them in there. 因此,每当您有一个以上的某种对象(DataProviders,FileReaders等)时,都为其创建一个名称空间/子命名空间并将其放置在其中。 So when your creating a new object/interface/enumeration... you always know where to put it. 因此,当您创建新的对象/接口/枚举...时,您始终知道将其放置在何处。 And you always know where to find again: Oh its a DataProvider so it must be located in ProjectName.Objects.DataProviders :) 而且您始终知道在哪里可以找到:哦,它是一个数据提供者,因此它必须位于ProjectName.Objects.DataProviders中:)

So my recommendation is: have some fun and read about: MVVM and SoC 所以我的建议是:玩得开心,并阅读以下内容:MVVM和SoC

Probably state machine diagram will help you do devide actions in parts. 状态机图可能会帮助您在零件中进行操作。 It's a better practice, to create some of diagrams before codding. 在编码之前先创建一些图是一种更好的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM