473,225 Members | 1,369 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,225 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 803

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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.