7 Replies - 2919 Views - Last Post: 03 November 2014 - 02:00 AM Rate Topic: -----

#1 josh_   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-November 14

MVP on simple Windows Form Application

Posted 01 November 2014 - 07:15 PM

I'm building a Windows Form Application using MVP Design Pattern; the application is quite simple, it just calculates the sum of two number; So I have a form in which are located tree textbox: number1 number2 and result, plus a button to perform the action.
interface ICalcView
    {
    string firstN { get; set; }
    string firstN {get; set;}
    string result { get; set; }
    }

    interface ICalcModel
    {
        public int Add();
    }

    interface ICalcPresenter
    {
        ICalcModel model;
        ICalcView view;
    }

 public class CalcView : Form,ICalcView{...
 public class CalcPresenter: ICalcPresenter{...
 public class CalcModel : ICalcModel{...

Do you think that is a good base to start? Can you provide me a code example to understand the execution flow and how to handle events?

Is This A Good Question/Topic? 0
  • +

Replies To: MVP on simple Windows Form Application

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6290
  • View blog
  • Posts: 21,618
  • Joined: 05-May 12

Re: MVP on simple Windows Form Application

Posted 01 November 2014 - 10:29 PM

No. Your model seem so be missing some way to transmit the information from the view into the model and back out again. Normally, you don't want the model talking to the view directly.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: MVP on simple Windows Form Application

Posted 02 November 2014 - 05:15 AM

Clearly this code doesn't compile and run.
Look at lines 3 and 4.
If you want us to evaluate your code that's cool, but you have to give us your real code that you have at least tried and debugged.
Was This Post Helpful? 0
  • +
  • -

#4 josh_   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-November 14

Re: MVP on simple Windows Form Application

Posted 02 November 2014 - 06:16 AM

This code is just an examples, I made it simple to know how to build a generally speaking MVP windows form pattern; in other words what you suggest to put inside the view, model and presenter?
By the way in the fourth line there's a typo.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is offline

  • Bouncy!
  • member icon

Reputation: 6563
  • View blog
  • Posts: 26,615
  • Joined: 12-December 12

Re: MVP on simple Windows Form Application

Posted 02 November 2014 - 06:32 AM

Quote

in other words what you suggest to put inside the view, model and presenter?

This sounds very much like you are asking us to guide you through the full process. I already have a tutorial for that.

Otherwise, you need to ask specific questions.

This post has been edited by andrewsw: 02 November 2014 - 06:37 AM

Was This Post Helpful? 1
  • +
  • -

#6 josh_   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-November 14

Re: MVP on simple Windows Form Application

Posted 02 November 2014 - 08:12 AM

The tutorial is too detailed, I just need to know, in general, how a simple program like this one should be under the mvp pattern.
In the model I put the method Add(int x, int y), which is called by the presenter.
The presenter has a property for the model and one for the view; the presenter calls methods and updates the view on certain events.
In the view I put those required values: the two numbers and the result:
public partial class WinFormAppView : Form, IWinFormAppView
    {
        public string firstNumber
        {
            get { return this.FirstNumberBox.Text; }
            set { this.FirstNumberBox.Text = value; }
        }...


Set in this way the code, violates the MVP pattern?
How can you describe a events handler system? (just in generics terms)
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: MVP on simple Windows Form Application

Posted 02 November 2014 - 08:30 AM

Sorry if the tutorial is beyond where you are right now. We can point you at the resources you need, but we can't know if you're ready for them yet. Keep working at the tutorial. Striving beyond your current point is how you move forward. Just keep working it and it will start making sense.

View Postjosh_, on 02 November 2014 - 09:12 AM, said:

  • in general, how a simple program like this one should be under the mvp pattern.
  • Set in this way the code, violates the MVP pattern?
  • How can you describe a events handler system? (just in generics terms)


Hmmm... By any chance are you trying to get us to write your essay or free-form quiz answers for you? It sounds like it.
Was This Post Helpful? 0
  • +
  • -

#8 josh_   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-November 14

Re: MVP on simple Windows Form Application

Posted 03 November 2014 - 02:00 AM

In general the presenter is able to interact directly with the instances of the view and the model,
when something happens the view can raises an event or more than one, at that point the presenter(that is a subscriber) catch the event and acts calling for example a method of the model.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1