Trainwreck
June 1st, 2009, 12:38 PM
I have an app that loads widgets, but i want to do this as close to a MVC structure as possible.
Suppose i have the following classes:
1. Index.cs
2. Handler.cs (for all the GUI stuff)
(The widgets)These files are forms, thus it only contain the GUI.
3. Users.cs
Feeds.cs
News.cs
What of the following examples is the closest to a MVC structure?
Scenario 1:
Index.cs creates an instance of Handler.cs.
Handler.cs creates an instance of all the widgets. So it has these instances:
Users users = new Users();
Feeds feeds = new Feeds();
News news = new News();
When i want to load the Feeds widget from Index.cs i do the following:
Index.cs
Handler handler = new Handler(this);
handler.ShowFeeds();
Handler.cs
//constructor
public Handler(Index index)
{
this.index = index; //take over the instance of Index.cs
feeds.Location = new Point(300,200);
index.Controls.Add(feeds);
}
public void ShowFeeds()
{
feeds.Show(); //Show() is a C# function.
}
Should i do it like this?? Or is the 2nd scenario better:
---------------
Scenario 2:
Index.cs creates an instance of everytinhg:
Handler handler;
Feeds feeds;
News news;
Users users;
Also loads the GUI elemens in its own class, but doesn't Show() them yet untill neccessary.
public void LoadAll()
{
feeds.Location = new Point(300,200);
this.Controls.Add(feeds);
news.Location = new Point(300,200);
this.Controls.Add(news);
users.Location = new Point(300,200);
this.Controls.Add(users);
}
And i just use Hanlder.cs to handle all the button clicks and stuff like that of all the GUI class files. Instead of Loading, Showing and Hiding
all the forms.
-----
So which one is better, or are they both not good...??
Suppose i have the following classes:
1. Index.cs
2. Handler.cs (for all the GUI stuff)
(The widgets)These files are forms, thus it only contain the GUI.
3. Users.cs
Feeds.cs
News.cs
What of the following examples is the closest to a MVC structure?
Scenario 1:
Index.cs creates an instance of Handler.cs.
Handler.cs creates an instance of all the widgets. So it has these instances:
Users users = new Users();
Feeds feeds = new Feeds();
News news = new News();
When i want to load the Feeds widget from Index.cs i do the following:
Index.cs
Handler handler = new Handler(this);
handler.ShowFeeds();
Handler.cs
//constructor
public Handler(Index index)
{
this.index = index; //take over the instance of Index.cs
feeds.Location = new Point(300,200);
index.Controls.Add(feeds);
}
public void ShowFeeds()
{
feeds.Show(); //Show() is a C# function.
}
Should i do it like this?? Or is the 2nd scenario better:
---------------
Scenario 2:
Index.cs creates an instance of everytinhg:
Handler handler;
Feeds feeds;
News news;
Users users;
Also loads the GUI elemens in its own class, but doesn't Show() them yet untill neccessary.
public void LoadAll()
{
feeds.Location = new Point(300,200);
this.Controls.Add(feeds);
news.Location = new Point(300,200);
this.Controls.Add(news);
users.Location = new Point(300,200);
this.Controls.Add(users);
}
And i just use Hanlder.cs to handle all the button clicks and stuff like that of all the GUI class files. Instead of Loading, Showing and Hiding
all the forms.
-----
So which one is better, or are they both not good...??