如何实现易于使用和可扩展的模式? [英] How do I implement a easy to use and scalable pattern?
问题描述
我目前正在开发一个更大的WinForms项目。我曾经使用最多有20个不同窗口的WinForms来编写小应用程序。
现在我面临一个更大的项目,并希望通过过度思考来适应这一点接近这个。
我读过关于MVVM和MVC以及一些变化的内容。
说到变化:我发现了很多变化,我不知道它们来自哪个实现。
我的想法是它有:
-easyily scalability
-clear关注点分离(SoC)
-直观的使用方式
关于这个项目的一些附注:
-Hotkey驱动的导航(每个视图可以有多个热键导航到其他视图)
- 需要快速响应时间(客户端不喜欢等待查询完成超过1秒。)
下面你会看到我目前关于如何使用模式的想法。
我非常感谢批评和/或提示这个。
另外,我非常感谢您听到有关如何使用此模式的建议以及是否存在任何陷阱如何避免它们。
提前谢谢你:)
我尝试过:
到目前为止,我设计了以下模式作为一种方法:
课程:
查看
I am currently working on a bigger WinForms project. I used to program small applications using WinForms that had a maximum of ~20 different windows.
Now I am facing a bigger project and want to adapt to that by overthinking my approach to that.
I have read about MVVM and MVC and some variations.
Speaking of variations: I found so many variations, that I have no idea which implementation they originated from.
My Idea is that it has:
-easily scalability
-clear seperation of concerns (SoC)
-an intuitive way of usage
Some side-notes on this project:
-Hotkey-driven navigation (every view can have multiple hotkeys to navigate to other views)
-Fast response time required (the client does not like to wait for a query to finish longer than 1 second.)
Below you will see my current idea of how to use a pattern.
I am very thankful for criticism and/or tips on this.
Also I would be very thankful to hear your suggestions on how to use this pattern and if any traps exists how to avoid them.
Thank you in advance :)
What I have tried:
So far I have designed the following pattern as an approach:
Classes:
View
void SetViewModel(ViewModel viewmodel);
void Clear();
思想:
查看只需要接受一个ViewModel类来显示。
视图中的所有逻辑都用于注册关键事件和按钮点击等。
如果出现类似的事件则会触发事件或者重定向到控制器的命令。
控制器
Thoughts:
The View only has to accept a ViewModel class to display.
All logic in the view is for registering key events and button clicks etc.
If something like that happens a event is fired or a command redirected to the Controller.
Controller
void AddView(View view);
void RemoveView(View view);
void SetModel(Model model);
void SetViewModel(ViewModel viewmodel);
思想:
我的控制器将包含所有与决策相关的逻辑。 (示例:如果单击按钮X查看 - 打开新视图)
它将接受视图(一个或多个)并更新每个视图。
ViewModel
Thoughts:
My controller will contain all decision-relevant logic. (example: If button X is clicked on View - Open new View)
It will accept views (one or many) and update every View.
ViewModel
event PropertyChangedEventHandler PropertyChanged;
T Get<T>(string property);
void Set<T>(string property, T value);
模型
Model
event PropertyChangedEventHandler PropertyChanged;
T Get<T>(string property);
void Set<T>(string property, T value);
想法:
模型和ViewModel几乎相似。
他们包含属性更改时实体和火灾事件的值。
转换器< TVM,TM>
Thoughts:
Model and ViewModel are almost similar.
They contain the values of the entity and fire events when a property changes.
Converter<TVM, TM>
TM ConvertToModel(TVM viewmodel);
TVM ConvertToViewModel(TM model);
想法:
我的转换器将负责将模型从ViewModel转换为Model并返回。他们需要处理与视图相关的转换并格式化特定的事物。
结论:
我不确定如何识别实现陷阱和可能事先有错误的设计选择,需要一些关于如何以一个整洁的模式来处理大项目的指导。
Thoughts:
My Converters will be responsible on converting models from ViewModel to Model and back. They will need to handle view-relevant conversions and formatting specific things.
Conclusion:
I am unsure how to identify implementation traps and possible faulty design choices beforehand and require some guidance on how to approach a big project with a neat pattern to follow.
推荐答案
DZone 有一个很好的关于原始Gang of Four设计模式的refcard,您可以免费下载(注册后):
https://dzone.com/refcardz/design-patterns?chapter=1 [ ^ ]
我还在一篇着名的CodeProjector( Richard McCutchan ): https://dzone.com/articles/design-patterns-c-factory [< a href = https://dzone.com/articles/design-patterns-c-factorytarget =_ blanktitle =新窗口> ^ ]
工厂模式是其中之一我认为最有用的,特别是如果你想在一个大解决方案中解耦类。
DZone has a nice refcard about the original Gang of Four design patterns which you can download for free (after signing up):
https://dzone.com/refcardz/design-patterns?chapter=1[^]
I also stumbled upon this article on DZone about the Factory pattern by a well known CodeProjector (Richard McCutchan): https://dzone.com/articles/design-patterns-c-factory[^]
The Factory pattern is one of the most useful I think especially if you want to decouple classes in a big solution.
也许你可以使用自定义表单,如下所示:
Maybe you can use custom forms, something like this:
public class CustomForm : Form
{
/// <summary>
/// Initializes a new instance of the <see cref="CustomForm"/> class.
/// </summary>
public CustomForm()
{
// Required for Windows Form Designer support
this.InitializeComponent();
}
private void CustomFormLoad(object sender, EventArgs e)
{
this.BackColor = SkinSettings.FormBackgroundColor;
this.ForeColor = SkinSettings.FormForegroundColor;
this.Font = SkinSettings.FontDefault;
if (this.Text == @"CustomForm")
{
this.Text = SkinSettings.ProductName;
this.Icon = SkinSettings.FormIcon;
}
}
}
这篇关于如何实现易于使用和可扩展的模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!