C# 任何 Windows 窗体应用程序最常见的设计模式是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/404624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the most common design patterns for any windows forms application?
提问by Ahmed Said
I am asking about that as I am going to develop a client side application using c# to display stock data and make some user-interaction, so give me links for best tutorials you read before
我在问这个,因为我将使用 c# 开发一个客户端应用程序来显示股票数据并进行一些用户交互,所以给我你之前阅读过的最佳教程的链接
采纳答案by Jimmy McNulty
Jeremy Miller's guideis an excellent starting place. It covers several important patterns including:
Jeremy Miller 的指南是一个很好的起点。它涵盖了几个重要的模式,包括:
- Model - View - Controller- There are several flavours, make sure you examine them all
- Automated unit testingof GUI binding code
- Command pattern
- Registry
- 模型 - 视图 - 控制器- 有几种风格,确保你都检查过它们
- GUI绑定代码的自动化单元测试
- 命令模式
- 注册表
You will also want to look at inversion of control and dependency inversion. Fowler's overviewdoes a good job of explaining the concept. When you've looked at this, here is a tutorialon just one implementation of an IoC tool.
您还需要查看控制反转和依赖反转。 Fowler 的概述很好地解释了这个概念。当你看到这个时,这里有一个关于 IoC 工具的一个实现的教程。
If you are still hungry for more, check out Rich Newman's serieson Microsoft's Composite Application Block. The CAB is chock full of patterns, but avoid the official documentation as it is notoriously difficult.
如果您仍然渴望获得更多,请查看Rich Newman关于 Microsoft 复合应用程序块的系列文章。CAB 充满了模式,但要避免使用官方文档,因为它是出了名的困难。
回答by johnc
To answer your question, the most common pattern appears to be generalized hacking in my experience, however if you want a nice pattern check out the MVP (Model View Presenter)pattern from Microsoft's Patterns and Practices group. Although it's an ASP.NET pattern, I modify it slightly to use on Winforms all the time.
要回答您的问题,根据我的经验,最常见的模式似乎是泛化黑客攻击,但是如果您想要一个不错的模式,请查看Microsoft 模式和实践组的MVP(模型视图展示器)模式。虽然它是一种 ASP.NET 模式,但我对其进行了轻微修改以一直在 Winforms 上使用。
It's a nice separation of concerns, and allows for unit test to be built through programming to interfaces (design by composition).
这是一个很好的关注点分离,并允许通过编程到接口(通过组合设计)来构建单元测试。
回答by Jared Harley
This is only a partial answer, but I really enjoy referencing the Windows Vista User Experience/Interaction Guide(there's a pdf link for the whole thing too). Most of it, of course, is directed at matching your application's look and feel to fit in with Vista.
这只是部分答案,但我真的很喜欢参考Windows Vista 用户体验/交互指南(整个内容也有一个 pdf 链接)。当然,其中大部分是为了匹配您的应用程序的外观以适应 Vista。
Some of it, though, applies universally - especiallythe sections on the differences of warnings, errors, and other messages, and when to use each. I find myself checking those guidelines every time I work on something that's going to make a pop-up - and the guide doesn't pull any punches when getting after Microsoft programs for breaking these guidelines.
但是,其中的一些内容是普遍适用的——尤其是关于警告、错误和其他消息的差异以及何时使用它们的部分。我发现每次我做一些会弹出窗口的事情时,我都会检查这些指导方针 - 当微软计划违反这些指导方针时,该指南并没有采取任何措施。
I don't know of a guide like this that exists for Windows XP.
我不知道 Windows XP 中存在这样的指南。