MVP checkbox implemetation in C#?
my task is to make an e.g. of MVP implementation. I want to have a CheckBox in my View (form) - its role is to switch visible true / false of some fields on form.
Do I need to put some some code to Presenter, to keep my project as MVP?
Right now I got all of things related to that checkbox in my View
Form1.Designercs :
public void SetTelephoneVisible()
{
this.telephone.Visible = true;
this.label5.Visible = true;
}
public void SetTelephoneInvisible()
{
this.telephone.Visible = false;
this.label5.Visible = false;
}
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
Form1.cs :
private void checkBox1_CheckedChanged(object se开发者_开发百科nder, EventArgs e)
{
if (checkBox1.Checked == true)
SetTelephoneVisible();
if (checkBox1.Checked == false)
SetTelephoneInvisible();
}
So, once again - Do I need to put some some code to Presenter, to keep my project as MVP? ... and how to do it?
PS: I can give u all of my code, if its needed to clarify sth
As long as hiding the phone number remains a purely UI, short-lived action, I wouldn't inform the presenter of that. You don't notify the presenter when the user opens a combo box do you ?
However things become different as soon as you start adding application or business logic to that (for instance, saving user preferences concerning field visibility).
In my opinion Model View Presenter is very broad term, there are different variants of it. But in general the purpose of every UI pattern is to separate logic from UI presentation. So the short "stupid" answer is yes. But again in my opinion this topic is more of philosophic nature, what logic to put in presenter... For example when a user scrolls ListBox collection of visible items changes, should you inform presenter on this and maintain a list of visible items? probably not if you don't need it, but this is logic... If you move all logic of you form in presenter you will end up in reinventing Controls.
If it effects your business logic or Model, maybe you should.
精彩评论