What normally goes inside an interface for controller? (mvc)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Robertsonjay
    New Member
    • Aug 2009
    • 1

    What normally goes inside an interface for controller? (mvc)

    In mvc you separate view from controller. How do you do that in C#?

    Many people define an interface for a controller but isn't controller is specific to a form(gui) which all controller contains is handle events from gui controls(button , treeviews, textboxes etc..) which you don't know until you code the form.

    So is there a point in having an interface for a controller where that controller is tightly tied to a specific form.

    Having said that, many people say that controller can be used with many forms - how? as i'm aware of is controller tied to specific gui controls (like is said above).

    Basically what i think a controller is for handling gui events and that is depending on gui controls. am i correct?

    If not, what is the correct way to do it? what goes inside interface for controller?

    thanks in advance
  • fastestindian
    New Member
    • Aug 2009
    • 74

    #2
    Hi Robert,

    Windows application.
    Code:
    public partial class Form1 : Form, IUserView
        {
            UserViewPresenter _presenter;
    
            public Form1()
            {
                InitializeComponent();
                _presenter = new UserViewPresenter(this);
                _presenter.SetCustomerData();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
            }
    
            #region IUserView Members
    
            public string FirstName
            {
                set { firstname.Text=value; }
            }
    
            public string LastName
            {
                set { lastName.Text = value; }
            }
    
            public string Address
            {
                set { address.Text = value; }
            }
    
            public string City
            {
                set { city.Text = value; }
            }
    
    
            public string ErrorMessage
            {
                set
                {
                    errorLabelMessage.Text = value;
                    errorLabelMessage.Visible = value != "";
                }
            }
    
            public string SearchCriteria
            {
                get { return searchCriteria.Text; }
            }
    
            #endregion
    
            private void searchButton_Click(object sender, EventArgs e)
            {
                _presenter.SetCustomerData();
            }
    
        }
    Asp.net Application
    Code:
    public partial class _UserView : Page, IUserView
    {
        private UserViewPresenter _presenter;
    
        protected void Page_Load(object sender, EventArgs e)
        {
            _presenter = new UserViewPresenter(this);
            _presenter.SetCustomerData();
        }
    
        protected void searchButton_Click(object sender, EventArgs e)
        {
            _presenter.SetCustomerData();
        }
    
        #region IUserView Members
    
        public string FirstName
        {
            set { firstName.Text = value; }
        }
    
        public string LastName
        {
            set { lastName.Text = value; }
        }
    
        public string Address
        {
            set { address.Text = value; }
        }
    
        public string City
        {
            set { city.Text = value; }
        }
    
        public string ErrorMessage
        {
            set
            {
                errorMessageLabel.Text = value;
                errorMessageLabel.Visible = value != "";
            }
        }
    
        public string SearchCriteria
        {
            get { return searchCriteria.Text; }
        }
    
        #endregion
    }
    From above code we learn that we seperate out User Interface from Data.
    so that same middle layer i.e. business logic need not to be change.

    Comment

    Working...