【发布时间】:2019-07-26 08:27:52
【问题描述】:
我想我遇到了设计问题。所以让我们从头开始。这就是我想要的:
一方面有组合框,需要填充,让用户在提供的功能之间进行选择。另一方面,必须调用此功能才能实现其目的。
我在想这样的事情,分散在 GUI 的某个地方:
// Parameter type describes what to do. This example shows that a CRC value
// shall be calculated. But it could be a quadratic formular or any other // calculation as well. So I assume parameter is of type IStrategy.
// And here I assume a further interface exist, lets say ICRCxx.
ChoiceProvider functionality = new ChoiceProvider(CRC16);
// Yes, I know about Items and binding. Method returns functionality
// provided by ICRCxx. For example just { "CRC32", "CRC16 CCITT" } will be
// returned at the moment.
string[] cellChoice_Of1stComboBox = functionality.GetCalculationNames();
bool functionality.SetCalculationName(string name);
// Here between start values can be chosen, necessary for the calculation.
// For example { "Ox0000", "Ox1D0F" } will be returned, if "CRC16 CCITT"
// has been selected above.
string[] cellChoice_Of2ndComboBox = functionality.GetCalculationVariants();
bool functionality.SetCalculationVariant(string name);
// to be displayed somewhere on GUI
string userResult = functionality.GetUserResult();
// Return type may vary depending on chosen calculation within.
var processResult = functionality.GetProcessResult();
// This is just a idea to be able to handle processResult.
// Maybe you have got a better idea. About that I had a struggle with
// generics.
Type processResultType = functionality.GetProcessType();
对不起,后面还有很多话。
我已经有了一个名为 ChoiceProvider 的类。我把它变成了通用的,因为首先我尝试了递归,以便能够组合尽可能多的 ComboBoxes。它基于字典>,因为我正在处理名称。 Ichoice>T> 中的 T 可以是任何类型的计算。
ChoiceProvider 已经在访问者模式下工作,作为操作员。但是我之前没有让它递归工作(没有模式)。
下面的访问者模式(访问者是 TChoice,访问者是 IStrategy)是一个可供选择的策略模式,例如如果 ICRCxx 已通过 IStrategy,则在 CRC16 或 CRC32 之间。运算符是例如收集提供的计算,因此如果 ICRCxx 已通过,则将收集具体策略类 CRC16 和 CRC32 作为可能的 ComboBox 选择。
但是,当从 Do_Strategy 类(意思是“计算”)到 Get_ProcessResult 类的方法 Visit(IVisited...) 之间传递数据时,我遇到了上面提到的泛型问题。因为我不是泛型专家。
首先我想问你关于我将数据从一个类传递到另一个类的问题,与泛型或类似的东西有关:How to force derived class to implement a static property or field?
但后来我意识到,我找不到一个好的问题来找到正确的答案(技术上或设计上)。所以现在我只问你关于设计的问题。
我现在认为访问者模式可能太复杂了。我现在只考虑下面的主要策略模式和第二个策略模式。但是我浪费了时间。在我重新开始新事物之前,我想走上一条成功的道路。所以我问你。
...
更新 - 简短:
我眼中的访客模式,在我看来并不是正确的方法。我想要更少的代码和更多的可扩展性。
我尝试了我所说的“与 GUI 连接的封闭功能”(见上文)。通常我会得到功能和 GUI 混合在一起的代码,我必须在 GUI 的某个地方找到开放的功能。
- 是否已经有任何简单的解决方案/代码可用于我的“封闭目的”?
- 我现在应该使用哪些有用的关键字? (例如“ORM”、“IQToolKit”……用于将 OleDb 连接到 OOCode。在我的情况下,我想将功能与例如 ComboBoxes 连接起来。)
【问题讨论】:
-
这样的问题对 SO 来说有点太宽泛了。也许software engineering 是一个更好的地方?
-
如何将我的问题转移到软件工程?是否有简单的点击或者我必须重新重写它?
标签: c# winforms combobox c#-7.3