我不太擅長OOP甚至C#,但我想盡量保持我的代碼儘可能乾淨。 可以說,我們已經有了類似的東西命名空間「GoogleCalendarNotificator」內:來自其他類和其他主要問題的控制表
public partial class MainForm : Form
{
private object calendarData;
public MainForm()
{
InitializeComponent();
}
private void recieveCalendarDataButton_Click(object sender, EventArgs e)
{
getCalendarDataBW.RunWorkerAsync();
}
private void getCalendarDataBW_DoWork(object sender, DoWorkEventArgs e)
{
try {
getCalendarData getCalendarDataObj = new getCalendarData();
calendarData = getCalendarDataObj.getData();
} catch (Exception err) {
statusHandler("Login Failed, Please check your Data", err.Message);
}
try {
workWithCalendarData workWithCalendarDataObj = new workWithCalendarData();
workWithCalendarDataObj.workWithData(calendarData, MainForm.ActiveForm);
statusHandler("New calendardata recieved");
} catch (Exception err) {
statusHandler("Login Failed, Please check your Data", err.Message);
}
}
public void statusHandler(string displayMessage, string tooltipMessage = null)
{
string curTime = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString();
statusLabel.Text = curTime + " - " + displayMessage;
if (tooltipMessage != null)
{
statusLabel.ToolTipText = "Original error message: " + tooltipMessage;
}
}
這是對ErrorHandling中好的解決辦法? 以及如何對這個部分:
workWithCalendarData workWithCalendarDataObj = new workWithCalendarData();
workWithCalendarDataObj.workWithData(calendarData, MainForm.ActiveForm);
我只是想給另一個類(workWithCalendarData)與MainForm的互動的可能性。但我不想簡單地寫在workWithCalendarData類是這樣的:
MainForm hehe = new MainForm();
hehe.DOSOMETHING();
我希望它是動態地,如果有人知道我的意思。就像給這個類提供與Form(a.e. MainForm.ActiveForm)一起工作所需的信息。
偉大的MVC模式,它被稱爲:)這最大限度地幫助我..我會繼續學習更多的信息呢? – botweb 2010-09-03 18:11:12