I'm not that good in OOP or even C# but I want to try to keep my code as clean as possible. Lets say we've got something like that within the Namespace "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;
}
}
Is this a good solution for ErrorHandling? And how about this part:
workWithCalendarData workWithCalendarDataObj = new workWithCalendarData();
workWithCalendarDataObj.workWithData(calendarData, MainForm.ActiveForm);
I simply want to give another class (workWithCalendarData) the possibility to interact with the MainForm. But I do not want simply written in the workWithCalendarData class something like:
MainForm hehe = new MainForm();
hehe.DOSOMETHING();
I want it to be dynamicly if anybody knows what I mean. Like give the class the Information needed to work with the Form (a.e. MainForm.ActiveForm).