Home  /  Questions  /  Question



250   96.9
Apr 24, 2016


MVP Pattern - A lot of questions

Hello,

I want to ask about MVP
after i tried, read and search i found some patterns and it makes me confused

1. Type - 1
public interface ILoginView {
        string Username { get; set; }
        string Password { get; set; }

        void Notify(string message);
        event EventHandler<EventArgs> Login;
    }

public partial class Form1 : Form, ILoginView {

        private LoginPresenter __presenter;

        public Form1() {
            InitializeComponent();
            __presenter = new LoginPresenter(this);
        }

        public event EventHandler<EventArgs> Login;

        public string Username {
            get { return textBox1.Text; }
            set { textBox1.Text = value; }
        }

        public string Password {
            get { return textBox2.Text; }
            set { textBox2.Text = value; }
        }

        public void Notify(string message) {
            MessageBox.Show(message);
        }

        private void button1_Click(object sender, EventArgs e) {
            if (Login != null) {
                Login(this, EventArgs.Empty);
            }
        }

        private void button2_Click(object sender, EventArgs e) {
            Close();
        }
    }

    public class LoginPresenter {
        ILoginView __view;

        public LoginPresenter(ILoginView view) {
            __view = view;
            __view.Login += doLogin;
        }

        private void doLogin(object sender, EventArgs e) {
            if (__view.Username == string.Empty) {
                __view.Notify("Username blank");
            } else if (__view.Password == string.Empty) {
                __view.Notify("Password blank");
            } else {
                __view.Notify("Success");
            }
        }
    }

 2.  Type - 2
public interface ILoginView {
        string Username { get; set; }
        string Password { get; set; }

        void Notify(string message);
    }

public partial class Form1 : Form, ILoginView {

        private LoginPresenter __presenter;

        public Form1() {
            InitializeComponent();
            __presenter = new LoginPresenter(this);
        }

        public string Username {
            get { return textBox1.Text; }
            set { textBox1.Text = value; }
        }

        public string Password {
            get { return textBox2.Text; }
            set { textBox2.Text = value; }
        }

        public void Notify(string message) {
            MessageBox.Show(message);
        }

        private void button1_Click(object sender, EventArgs e) {
            __presenter.Login();
        }

        private void button2_Click(object sender, EventArgs e) {
            Close();
        }

    public class LoginPresenter {
        ILoginView __view;

        public LoginPresenter(ILoginView view) {
            __view = view;
        }

        public void Login() {
            if (__view.Username == string.Empty) {
                __view.Notify("Username blank");
            } else if (__view.Password == string.Empty) {
                __view.Notify("Password blank");
            } else {
                __view.Notify("Success");
            }
        }
    }
of the sample which is right about MVP ?

and about internationalization and prepare control, i want to internationalization every label in my winforms
with mvp how do I do this?
this following code

private void __setLocalize() {
            lblHeader.Text = "SelectActivationMethod".Internationalize();

            lblLicense.Text = "License".Internationalize();
            lblLicenseType.Text = "LicenseType".Internationalize();
            lblKeyStatus.Text = "LicenseKeyStatus".Internationalize();
            lblLicenseStatus.Text = "LicenseStatusEvaluation".Internationalize();
            lblRemaining.Text = "LicenseRemaining".Internationalize();

            OptContinueEvaluation.Text = "ContinueEvaluation".Internationalize();
            lblContinueEvaluationInformation.Text = "ContinueEvaluationInformation".Internationalize();
            
            OptActivateCommercialVersion.Text = "ActivateCommercialVersion".Internationalize();
            lblEnterActivationCode.Text = "EnterActivationCode".Internationalize();
            CmdActivate.Text = "Activate".Internationalize();
            txtPurchase.Text = "LicensePurchaseInformation".Internationalize();

            CmdNext.Text = "Next".Internationalize();
            CmdCancel.Text = "Cancel".Internationalize();
        }

        private void __prepareControl() {
            CmdActivate.Enabled = false;
            txtActivationCode.Enabled = false;
            txtActivationCode.Text = string.Empty;
            OptContinueEvaluation.Checked = true;
        }

        private void Evaluations_Load(object sender, EventArgs e) {
            __setResource();
            __setLocalize();
            }
        }
using MVP I have to put it all in presenter ?

Best regards,
Eric Santoso
 
MVP