1 Replies - 748 Views - Last Post: 05 February 2011 - 02:49 AM Rate Topic: -----

#1 silwal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-February 11

Interface and Class member problem, MVC - Please help

Posted 04 February 2011 - 08:00 PM

I am newbie and need your kind help. I am trying to implement MVC in a windows application which adds two number.

I have defined interface in forms.cs as below:
 //Interface definition for VIEW.
    interface iAddrView
    {
        void addListener(iAddrController controller);

        string sum
        {
            get;
            set;
        }
    }


    //Interface definition for CONTROLLER.
    public interface iAddrController
    {
        void onclick (int operands);
        void adder();
    }

    
    //Interface definition for MODEL
    interface iAddrModel
    {
        int setInput(int number);
        //Supplied number processing and returning result. 
        
        int adds(int operand1, int operand2);
        //Adds two supplied operands.
        void toAddState();
        //Change state to adding

        //int subs(int operand1, int operand2);
        //void toSubState();
        //Subtraction not implemented.
    }



I have separate class file which inherits the interface. My class file is as follows:
Controller Class
namespace simpleAdder
{

     
    class saController : iAddrController

    {
       

        iAddrModel model;
        iAddrView  view;


        public saController(iAddrModel model, iAddrView view)
        {
            this.model = model;
            this.view  = view;
            this.view.addListener(this);
        }

        public void onclick( int operands )
        {
            view.sum = model.setInput(number).ToString();
        }

        public void adds()
        {
            model.toAddState();
        }

    }


Model Class
namespace simpleAdder
{
    class saModel : iAddrModel
    {
        public enum States { NoOperation, Add, Subtract };
        States state;
        int currentValue;

        public States State
        {
            set { state = value; }
        }

        public int SetInput(int number1)
        {
            if (state == States.NoOperation)
            {
                currentValue = number1;

            }
            else if (state == States.Add)
            {
                currentValue = Add(currentValue, number);
            }

            return currentValue;
        }

        public void toAddState()
        {
            this.state = States.Add;
        }

        public int adds(int operand1, int operand2)
        {
            return operand1 + operand2;
        }

        //public int Subtract(int value1, int value2)
        //{
        //    throw new System.ApplicationException(" Not implemented yet");
        //}
    }


View Class
public partial class saView : Form1, iAddrView
    {
        iAddrController controller;

        public saView()
        {
            InitializeComponent();

        }

        /// <summary>
        /// The view needs to interact with the controller to pass the click events
        /// This could be done with delegates instead.
        /// </summary>
        /// <param name="controller"></param>
        public void addListener(iAddrController controller)
        {
            this.controller = controller;
        }

        private void lbl_Click(object sender, EventArgs e)
        {
            // Get the text out of the label to determine the letter and pass the click info the controller to distribute.
            controller.onclick((Int32.Parse(((Label)sender).Text)));
        }

        private void lblPlus_Click(object sender, EventArgs e)
        {
            controller.adder();
        }

        #region iAddrView Members

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

        #endregion


    }



The problem is as I build, it is shows an error saying


Error 1 'simpleAdder.saModel' does not implement interface member 'simpleAdder.iAddrModel.setInput(int)'

Please kindly help me on this.

Is This A Good Question/Topic? 0
  • +

Replies To: Interface and Class member problem, MVC - Please help

#2 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 991
  • View blog
  • Posts: 971
  • Joined: 30-September 10

Re: Interface and Class member problem, MVC - Please help

Posted 05 February 2011 - 02:49 AM

Your interface member's signature is:

setInput(int)


...in you saModel class, you have implemented:

SetInput(int)


One has a capital 's' one doesn't :).


It's because of things such as this why you should standardize your capitalisation and naming conventions.

http://msdn.microsof...y/ms229002.aspx

This post has been edited by CodingSup3rnatur@l-360: 05 February 2011 - 02:52 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1