Click to See Complete Forum and Search --> : Theoretical question: MVC structure


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...??

vcdebugger
June 2nd, 2009, 04:44 AM
In the first case you are loading the required form whenever it is needed... but in the second case you are loading all the 3 form at one shot... the first one seems to be better in terms of performance as you are loading the form only upon the need where as in the second case you are loading all the 3 forms which might take more resource...