471,348 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Arrays and inheritence

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.
Jun 27 '08 #1
0 754

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Digital Puer | last post: by
5 posts views Thread by john bailo | last post: by
reply views Thread by Jan Elbæk | last post: by
19 posts views Thread by JKop | last post: by
7 posts views Thread by preetam | last post: by
11 posts views Thread by Vincent van Beveren | last post: by
2 posts views Thread by David | last post: by
5 posts views Thread by Neelesh Bodas | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.