寻找更好的设计模式 [英] searching for a better design pattern
问题描述
我花了数年时间编程程序化的风格但是因为项目越来越大我想清理一下并进入设计模式的东西 - 对于初学者很难概述这些丰富的技术!
i spend years programming the procedural kind of style but since the projects getting bigger i want to clear things up and get into the design pattern stuff - for a beginner it is rather hard to overview this rich amount of techniques!
所以我遇到了某种问题,这个问题可能解决得非常不理想(由于缺乏时间和泄漏知识) - 所以我现在非常感兴趣如何做到这一点的最佳实践方式... ???
so i have come up to a certain kind of problem which is solved perhaps very suboptimal (due to a lack of time and leaking knowledge) - so i am now very interest how to do this the best practise kind of way...???
实现目标:
i想要有一个协议类,实际上只收集某种信息。新添加的信息应该通知/反映到ui /调用者/连接类 - 比如更新一些包含此信息的控件。
the aim to achieve:
i want to have a protocol class which is actually only collecting some kind of information. newly added information should be notified/reflect to the ui / caller / connected class - doing like update some control containing this informations.
环境:
例如i构建了一个winform,其中包含一个显示协议数据的控件,如果我有某种helper-class,buisiness-layer,那么将协议添加到协议中是很好的,这是更新表单ui ...
environment:
for example i built a winform containing a control which is showing the data of the protocol, if i have some kind of helper-class, buisiness-layer aso it would be nice to add entries to the protocol which is the updating the forms ui...
所以这是我非常简单的素描:
so here is my very simple kept sketch:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Protocol.Device = lstbxLog; // set the global output device
}
private void btnForm1_Click(object sender, EventArgs e)
{
Protocol.AddEntry("Eintrag aus Form1", false);
}
private void btnHelper1_Click(object sender, EventArgs e)
{
new Helper1().DoSomething(); // call Protocol.AddEntry indirectly, in case to show error-msg occured
}
private void btnHelper2_Click(object sender, EventArgs e)
{
new Helper2().DoSomethingOther(); // call Protocol.AddEntry indirectly, in case to show error-msg occured
}
private void btnGetAll_Click(object sender, EventArgs e)
{
// the whole protocol could be set to a file or other device...
StringBuilder str = new StringBuilder();
foreach(string s in Protocol.Data)
str.Append(s+"\n");
MessageBox.Show(str.ToString());
}
}
推荐答案
可能
观察者模式帮助你。
这篇关于寻找更好的设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!