none
Help me get the faintest grasp on MVP RRS feed

  • Question

  • I'm trying to just get some sort of caveman understanding of how MVP works.  I made a new project with 4 files: Entrance.cs, Form1.cs (+ designer files), IView.cs, and LolPresenter.cs.  Entrance is the location of the program's entry point.

    Here's some code:
    Entrance.cs
    class Entrance
    {
        static void Main()
        {
            Application.Run(new Form1());
        }
    }

    Form1.cs (not all code shown)
    public partial class Form1 : Form, IView
    {
        // ...
    
        #region IView Members
    
        public string AStringLulz
        {
            get { return button1.Text; }
            set { button1.Text = value; }
        }
    
        #endregion
    
        private void button1_Click(object sender, EventArgs e)
        {
            LolPresenter presenter = new LolPresenter(this);
            presenter.ChangeString();
        }

    IView.cs
    interface IView
    {
        string AStringLulz { get; set; }
    }

    LolPresenter.cs
    class LolPresenter
    {
        IView something;
    
        public LolPresenter(IView view)
        {
            something = view;
        }
    
        public void ChangeString()
        {
            something.AStringLulz = "hahaha";
        }
    }

    Questions:
    1. Is this even an example of MVP? I know there's no model, so I guess my question is, is this even an example of VP?  What do I need to change to make it correctly follow the design?
    2. button1_Click looks really weird.  Is that really what I'm supposed to do?
    Thanks for any help, sorry for my ineptitude.
    Tuesday, April 21, 2009 7:03 PM

Answers

  • Hi

    Some links are provided for MVP design pattern,

    Model View Presenter
    • http://msdn.microsoft.com/en-us/magazine/cc188690.aspx


    Model View Presenter (MVP) design pattern close look - Part 1 (Supervising Controller)
    • http://blog.vuscode.com/malovicn/archive/2007/10/25/model-view-presenter-mvp-design-pattern-close-look-part-1-passive-view.aspx

    Model View Presenter (MVP) design pattern close look - Part 2 - Passive View

    • http://blog.vuscode.com/malovicn/archive/2007/11/04/model-view-presenter-mvp-design-pattern-close-look-part-2-passive-view.aspx

    Hope that the links are help for you.

    Regards,
    Phijo Mathew Philip.
    PHIJO MP
    • Marked as answer by sam.p Thursday, April 23, 2009 4:53 PM
    Thursday, April 23, 2009 1:06 AM

All replies

  • Hi

    Some links are provided for MVP design pattern,

    Model View Presenter
    • http://msdn.microsoft.com/en-us/magazine/cc188690.aspx


    Model View Presenter (MVP) design pattern close look - Part 1 (Supervising Controller)
    • http://blog.vuscode.com/malovicn/archive/2007/10/25/model-view-presenter-mvp-design-pattern-close-look-part-1-passive-view.aspx

    Model View Presenter (MVP) design pattern close look - Part 2 - Passive View

    • http://blog.vuscode.com/malovicn/archive/2007/11/04/model-view-presenter-mvp-design-pattern-close-look-part-2-passive-view.aspx

    Hope that the links are help for you.

    Regards,
    Phijo Mathew Philip.
    PHIJO MP
    • Marked as answer by sam.p Thursday, April 23, 2009 4:53 PM
    Thursday, April 23, 2009 1:06 AM
  • Thanks for the reply!  I have another question: if a model is updated by an another component (not a presenter) and I wish to update a view when this happens, should I have the appropriate presenter subscribe to the appropriate events of the outside component?

    Edit: or can I put Changed events inside the models?
    Edit: or should I have a presenter get passed the data from the outside component and have it update the model?  I'd think this is the right way to go, but I'm confused by what exactly Presenters should be handling.
    Thursday, April 23, 2009 4:53 PM
  • Your model could certainly be updated by external events.  No problem with that at all.  However, your presenter should be responsible for updating your view.  So if you want the event to be recognized and pushed out to the view i would wire up your presenter to be aware of any changes so that it can maintain control.
    Andrew Siemer www.andrewsiemer.com blog.andrewsiemer.com www.socialnetworkingin.net
    Thursday, April 23, 2009 5:58 PM