hi Aland Li
I am thinking to making polymorphism (( polymorphism based interfaces or polymorphism based inheritance)) Lke that
// This is the Base Class , It may be an Interface
public abstract class BaseClass
{
public abstract int A
{
get;
set;
}
public abstract int B
{
get;
set;
}
public abstract int C
{
get;
set;
}
public abstract int CalcValue();
}
// this is derived class
public class Class1:BaseClass
{
private int a;
private int b;
private int c;
public override int A
{
get
{
return a;
}
set
{
a = value;
}
}
public override int B
{
get
{
return b;
}
set
{
b = value;
}
}
public override int C
{
get
{
return c;
}
set
{
c = value;
}
}
public override int CalcValue()
{
// add implementation1
}
}
// this is another derived class
public class Class2:BaseClass
{
private int a;
private int b;
private int c;
public override int A
{
get
{
return a;
}
set
{
a = value;
}
}
public override int B
{
get
{
return b;
}
set
{
b = value;
}
}
public override int C
{
get
{
return c;
}
set
{
c = value;
}
}
public override int CalcValue()
{
// add implementation2
}
}
// this is another derived class
public class Class3:BaseClass
{
private int a;
private int b;
private int c;
public override int A
{
get
{
return a;
}
set
{
a = value;
}
}
public override int B
{
get
{
return b;
}
set
{
b = value;
}
}
public override int C
{
get
{
return c;
}
set
{
c = value;
}
}
public override int CalcValue()
{
// add implementation3
}
}
// Note here the type of the collection ((Baseclass))
public class MyBindingList:BindingList <BaseClass >
{
}
// In the Main Form
public partial class Form1 : Form
{
private MyBindingList _MyBindingListObj ;
public MyBindingList MyBindingListObj
{
get { return _MyBindingListObj; }
set { _MyBindingListObj = value; }
}
public Form1()
{
InitializeComponent();
MyBindingListObj = new MyBindingList();
dataGridView1.DataSource = MyBindingListObj;
}
private void button1_Click(object sender, EventArgs e)
{
// Add object of type Calss1 to a DataGridView
BaseClass obj1 = new Class1();
MyBindingListObj.Add(obj1);
}
private void button2_Click(object sender, EventArgs e)
{
//Add object of type class2 to a DataGridView
BaseClass obj2 = new Class2();
MyBindingListObj.Add(obj2);
}
private void button3_Click(object sender, EventArgs e)
{
//Add object of type class3 to a DataGridView
BaseClass obj3 = new Class3();
MyBindingListObj.Add(obj3);
}
I will be happy ,if you tell me your opinion
Alladeen