473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 810

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John | last post by:
Hi, I am trying to create a class heirarchy similar to the following: // base interface class ICar { public: virtual void start() = 0; }; // add members to that interface, but retain base...
8
by: Digital Puer | last post by:
I made the following table to help me (re)learn inheritence basics. Can someone check if it's correct? This table requires a courier-like font. Java C++ ---- ...
5
by: john bailo | last post by:
For a c# web application, I created a user control that includes a form in control. The idea is, on the main Page, when the user clicks Submit from the master form, that makes the user control...
0
by: Jan Elbęk | last post by:
Hi, I would like to make a base form in my project - which (almost) all forms must inherit from. The baseform must have some visible elements (a toolbar, a topaligned panel and a picturebox and...
16
by: gorda | last post by:
Hello, I am playing around with operator overloading and inheritence, specifically overloading the + operator in the base class and its derived class. The structure is simple: the base class...
19
by: JKop | last post by:
Been thinking about the following: class Mammal { public: virtual void Mate(Mammal &) = 0; };
7
by: preetam | last post by:
Hi, This question is more towards design than towards c++ details. By looking at books on design patterns and various google threads on the same topic, I see that composition is favoured to...
11
by: Vincent van Beveren | last post by:
Hi everyone, I have the following code using inheritence The important part is the function getName(). The result should alert 'John Doe': function First(name) { this.name = name; ...
2
by: David | last post by:
Hi all, I am fairly new to C#. so go easy on me :-) Anyhow, I have a class file that I have set up properties and a method. I am calling this class file directly from and aspx.cs file. So...
5
by: Neelesh Bodas | last post by:
This might be slightly off-topic. Many books on C++ consider multiple inheritence as an "advanced" concept. Bruce Eckel says in TICPP, volume 2 that "there was (and still is) a lot of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.