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.

New Topic/Question
Reply




MultiQuote





|