Hi,
I have a class called StatusType.
public class StatusType: ICloneable, IComparable<StatusType>
{
int id; // id as stored in statusType table
public int Id
{
get { return id; }
}
....
I also have a class called StatusTypes which looks something like this
-
public class StatusTypes: ICloneable, IEnumerable
{
StatusType[] statusTypes;
public StatusType this[int statusTypeId] // Indexer
declaration
{
get
{
foreach (StatusType statusType in statusTypes)
if (statusType.Id == statusTypeId)
return statusType;
return null;
}
}
public int Length{get { return statusTypes.Length; }}
// returns "P/F/A" for Passed, Failed, Aborted status types
public string StringRepresentation
{
get
{
string returnString = "";
if (statusTypes.Length 0)
returnString =
statusTypes[0].NameInitial.ToString();
for(int i=1;i<statusTypes.Length;i++)
returnString += @"/" +
statusTypes[i].NameInitial.ToString();
return returnString;
}
}
// populate from the statusType table
public StatusTypes(dataSet.statusTypeDataTable statusType)
{
statusTypes = new StatusType[statusType.Count];
int index = 0;
foreach (DataRow statusTypeDataRow in statusType.Rows)
statusTypes[index++] = new
StatusType(statusTypeDataRow as dataSet.statusTypeRow);
Array.Sort(statusTypes);
}
public object Clone()
{
StatusTypes clonedStatusTypes =
(StatusTypes)this.MemberwiseClone();
clonedStatusTypes.statusTypes = new
StatusType[statusTypes.Length];
int index = 0;
foreach (StatusType statusType in statusTypes)
clonedStatusTypes.statusTypes[index++] =
(StatusType)statusType.Clone();
return clonedStatusTypes;
}
IEnumerator IEnumerable.GetEnumerator() { return
statusTypes.GetEnumerator(); }
}
Since I'm still learning C#, is this implementation reasonable? One
thing I'm wondering about is the fact that I have a public accessor to
StatusType:id. The fact is that this is only accessed by StatusTypes.
It feels to me that StatusTypes should have access to private or
protected members of StatusType since this feel like a kind of
inheritance to me. How would I implement this?
Thanks,
Barry.