CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2005
    Posts
    134

    Theoretical question: MVC structure

    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:
    Code:
    Index.cs
    Handler handler = new Handler(this);
    handler.ShowFeeds();
    Code:
    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.
    Code:
    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...??

  2. #2
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: Theoretical question: MVC structure

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured