I have field which is private as per OOP, the field is arrayed to represent different channels, my orginal plan is to use structure to combine field together and then create array. Below belong to specific window application class which is designed to be standalone.
public struct DataDisplayStruct
{
public string m_preample;
public bool m_enable;
public string m_coupling;
public float m_position;
public float m_offset;
public float m_voltDiv;
}
public DataDisplayStruct[] DataDisplay = { new DataDisplayStruct(), new DataDisplayStruct(), new DataDisplayStruct(),new
DataDisplayStruct(),new DataDisplayStruct(), new DataDisplayStruct()};
I created the object from the other class (form1) implementing "Display myTek = new Display()" However this seem to break the OOP rule as the field is exposed and must apply property for data validation. So I need to make field private, but I came up all sort of problem in channeling data transfer betwen classes, the damn complier does not know how to stop complaining!!.
Based on pass Expert Exchange and textbooks, I learn two method but does not solve problem....may be I missed something from my learning curve:-
Method A:- Indexor is a neat solution but how to make it unquie to field?. The complier complain since there is too many same type but unable to find reference to seperates indexor according to name rather than type:-
private float[] m_voltDiv = new float[6];
private float this[int index]
{
get {return m_voltDiv[index];}
set {m_voltDiv[index]=value;}
}
private float[] m_offset = new float[6];
private float this[int index3]
{
get {return m_offset[index3];}
set {m_offset[index3]=value;}
}
private float[] m_position = new float[6];
private float this[int index2]
{
get {return m_position[index2];}
set {m_position[index2]=value;
}
}
private string[] m_preample= new string[6];
private bool[] m_enable= new bool[6];
private string[] m_coupling= new string[6];
Would not work...is there way around this?.
Method B:- found from previous ee, which they call it fake interface:- This is very neat but unable to find further reference to extend this methodm, anyone offer suggestion how to extend this to cover additional field variable?. As it stand it only deal one type, same problem as indexor.
public interface IDisplayData
{
int[] this[int index] { get; set; }
}
public class TekDataDisplay : System.Windows.Forms.Form,
IDisplayData
{
.............
public TekDataDisplay()
{
InitializeComponent();
m_data[0] = new int[10000]; //This is part of jagged array where init take place
m_data[1] = new int[10000];
m_data[2] = new int[10000];
m_data[3] = new int[10000];
m_data[4] = new int[10000];
m_data[5] = new int[10000];
}
............
int[] IDisplayData.this[int index]
{
get {return m_data[index];}
set {m_data[index]=value;}
}
public IDisplayData RecordData //TekDisplay.RecordData[0]
=myTek.Tek
Data_Wavef
ormData;
{
get {return this;} //this = TekVisaCS1....
}
Riscy.
Start Free Trial