473,414 Members | 1,698 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,414 software developers and data experts.

Designing a Collection class

Hi,

I have a hypothetical class called MyFiles which stores an array of
objects of type MyFile. MyFiles contains functions like
GetOldestFile(), GetLargestFile(), etc.

class MyFiles
{
MyFile[] myFiles;

public MyFiles(MyPath path)
{
myFiles = ...
}
}

When implementing the MyFiles class, is there any way to expose the
private members of MyFile for MyFiles? Or must I create accessors? For
me, it feels like MyFiles is inheriting from MyFile even though this
inheritance is not specified in code. Does this make sense?

Thanks for your help,

Barry
Jun 27 '08 #1
2 1035
On Jun 25, 7:28 am, bg...@yahoo.com wrote:
Hi,

I have a hypothetical class called MyFiles which stores an array of
objects of type MyFile. MyFiles contains functions like
GetOldestFile(), GetLargestFile(), etc.

class MyFiles
{
MyFile[] myFiles;

public MyFiles(MyPath path)
{
myFiles = ...
}

}

When implementing the MyFiles class, is there any way to expose the
private members of MyFile for MyFiles? Or must I create accessors? For
me, it feels like MyFiles is inheriting from MyFile even though this
inheritance is not specified in code. Does this make sense?

Thanks for your help,

Barry
If i have understood you correctly,
you could do the following

class MyFiles : List<MyFile>
{
public new MyFile this[int a]
{
get
{
return base[a];
}
}
}

public class MyFile
{
public string Name { get; set; }

}
in your code, you can have

MyFiles f = new MyFiles();
MyFile ff = new MyFile();
ff.Name = "P";

f.Add(ff);

Console.WriteLine(f[0].Name);
Jun 27 '08 #2
Just a List<MyFileor a Collection<MyFileshould do.

Note that LINQ might also solve a lot of those "biggest/oldest" issues
too... (note you could add extra extension methods to avoid the two-
pass approach here...)

List<MyFilefiles = new List<MyFile>();
long biggestSize = files.Max(file =file.Size);
MyFile biggestFile = files.FirstOrDefault(file =file.Size ==
biggestSize);
DateTime oldestDate = files.Min(file =file.Created);
MyFile oldestFile = files.FirstOrDefault(file =file.Created
== oldestDate);

Marc
Jun 27 '08 #3

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

Similar topics

12
by: James Brown | last post by:
Hi all, Having problems designing a template-class. I'll describe my scenario first then show what I've come up with so far: Need a class to provide pointer/array-like access to an area of...
6
by: Darren | last post by:
X-No-Archive Hi all, Can anyone help me with structuring the data in a small tool I have to build? I'm trying to work out if there's a design pattern or data structure that would remove some...
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
2
by: Sky Sigal | last post by:
Hello: I'm currently messing around, and need as much feedback/help as I can get, trying to find the most economical/graceful way to build usercontrols that rely on styling to look any good... ...
0
by: Julia Beresford | last post by:
Hi I have a VB .NET class library with classes and collection classes (classes that implement ICollection) that allow a client to read and write data to and from an SQL database. For example if...
2
by: Lorenzo Castelli | last post by:
This is an old problem of mine. Basically I have an abstract base class which represents a generic iterator over a collection of elements, and various derived classes that implement the...
6
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
6
by: Zim Babwe | last post by:
VS 2005 Windows Application I need to have users enter product information, then contact information, then some other financial information. Currently I have a form that the user enters info...
1
weaknessforcats
by: weaknessforcats | last post by:
Introduction Polymorphism is the official term for Object-Oriented Programming (OOP). Polymorphism is implemented in C++ by virtual functions. This article uses a simple example hierarchy which...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.