473,569 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating Custom Collection

Dear All,

I am trying to decide on to create a collection object for a project that I
am working on. I am fairly new to OOP so this may be on the basic side. I
have looked on the groups, but can't seem to find the answer I am looking for
- just more questions!

I want an object to hold Case details, one of the properties of this Case
class will be RequestedBy. I ideally want this property to be a collection
of User Objects (which will contain name, telephone, department etc).

My thinking is that I would have a Class Case with a property of RequestedBy
(of type Users) and the Users collection will have an indeterminate number of
User objects.

What is the best way for me to create the Users collection? From what I
have read I can either:
Create my own Collection by implementing the IEnumerable/IEnumerator interface
OR
Implement a pre-written Collection Interface for example IDictionary
OR
Implement the Class, for example Dictionary and my calls to base.Add for
example.

Is there a preferred way to do this? It seems to be such a fundamental
thing to do and whilst there is a great deal of information on the different
methods, there doesn't seem to be anything on how and when to use different
strategies.

I look forward to any help!

Regards

Mike Swann
Jun 26 '06 #1
6 5143
Why not use List<UserObject , userIndex>?
--
Jeffrey Hornby
Hornby Consulting, Inc.

"MikeSwann" wrote:
Dear All,

I am trying to decide on to create a collection object for a project that I
am working on. I am fairly new to OOP so this may be on the basic side. I
have looked on the groups, but can't seem to find the answer I am looking for
- just more questions!

I want an object to hold Case details, one of the properties of this Case
class will be RequestedBy. I ideally want this property to be a collection
of User Objects (which will contain name, telephone, department etc).

My thinking is that I would have a Class Case with a property of RequestedBy
(of type Users) and the Users collection will have an indeterminate number of
User objects.

What is the best way for me to create the Users collection? From what I
have read I can either:
Create my own Collection by implementing the IEnumerable/IEnumerator interface
OR
Implement a pre-written Collection Interface for example IDictionary
OR
Implement the Class, for example Dictionary and my calls to base.Add for
example.

Is there a preferred way to do this? It seems to be such a fundamental
thing to do and whilst there is a great deal of information on the different
methods, there doesn't seem to be anything on how and when to use different
strategies.

I look forward to any help!

Regards

Mike Swann

Jun 26 '06 #2
It depends on what version of the framework you're using

2.0
Use System.Collecti ons.Generics.Li st<User> directly (i.e. no need to define
a new collection class).

1.1
Inherit a new class from CollectionBase (do a search in the docs and you
should find an article on how to do that)
/claes
"MikeSwann" <Mi*******@news groups.nospam> wrote in message
news:09******** *************** ***********@mic rosoft.com...
Dear All,

I am trying to decide on to create a collection object for a project that
I
am working on. I am fairly new to OOP so this may be on the basic side.
I
have looked on the groups, but can't seem to find the answer I am looking
for
- just more questions!

I want an object to hold Case details, one of the properties of this Case
class will be RequestedBy. I ideally want this property to be a
collection
of User Objects (which will contain name, telephone, department etc).

My thinking is that I would have a Class Case with a property of
RequestedBy
(of type Users) and the Users collection will have an indeterminate number
of
User objects.

What is the best way for me to create the Users collection? From what I
have read I can either:
Create my own Collection by implementing the IEnumerable/IEnumerator
interface
OR
Implement a pre-written Collection Interface for example IDictionary
OR
Implement the Class, for example Dictionary and my calls to base.Add for
example.

Is there a preferred way to do this? It seems to be such a fundamental
thing to do and whilst there is a great deal of information on the
different
methods, there doesn't seem to be anything on how and when to use
different
strategies.

I look forward to any help!

Regards

Mike Swann

Jun 26 '06 #3
Hi Mike,

Thank you for posting.

You needn't create your custom user collection. .NET has provided several
kinds of collections for you, which you can use directly.

If you are using VS.NET2003, you may choose ArrayList or Hashtable(in
System.Collecti ons namespace).
If you are using VS2005, you may choose List<T> or Dictionary<T>(i n
System.Collecti ons.Generic namespace).

FYI, ArrayList and List<T> are used when you have an ordered collection of
items that do not have a key. Hashtable and Dictionary<T> are used when you
have an unordered collection of items that have a key.

Hope this helps.
If you have anything unclear, please don't hesitate to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =======
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
=============== =============== =============== =======

Jun 27 '06 #4

Hi Linda,

Thanks for your help.

I am thinking about using the Dictionary Class, however should I be
inherting the class and exposing the base methods (ie base.Add) or should I
be creating a local dictionary variable and then exposing the local methods
(ie localDictionary .Add).

It's more the theory of OO that I am struggling with I think!

Any help would be greatly aprreciated!

Thanks

Mike

"Linda Liu [MSFT]" wrote:
Hi Mike,

Thank you for posting.

You needn't create your custom user collection. .NET has provided several
kinds of collections for you, which you can use directly.

If you are using VS.NET2003, you may choose ArrayList or Hashtable(in
System.Collecti ons namespace).
If you are using VS2005, you may choose List<T> or Dictionary<T>(i n
System.Collecti ons.Generic namespace).

FYI, ArrayList and List<T> are used when you have an ordered collection of
items that do not have a key. Hashtable and Dictionary<T> are used when you
have an unordered collection of items that have a key.

Hope this helps.
If you have anything unclear, please don't hesitate to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =======
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
=============== =============== =============== =======

Jun 27 '06 #5
Hi Mike,

Thanks for your quick response.

I don't think you should inherite the Dictionary<T> class. You could use it
directly in your program. Just define a local dictionary variable of type
Dictionary<T> in your class and write a property to expose it. The code
may be something like below:

public class Case
{
private Dictionary<stri ng,User> users;
public Case()
{
users = new Dictionary<stri ng,User>();
}
public Dictionary<stri ng,User> Users
{
get { return users; }
}
}

You can access the Users property outside the class Case(but can't set the
property in this case for there's no set procedure in this property) and
call all the methods of Dictionary class.

Hope this helps.
If you have anything unclear, please don't hesitate to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =======
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
=============== =============== =============== =======

Jun 27 '06 #6
"MikeSwann" <Mi*******@news groups.nospam> a écrit dans le message de news:
4A************* *************** **...icrosof t.com...

| I am thinking about using the Dictionary Class, however should I be
| inherting the class and exposing the base methods (ie base.Add) or should
I
| be creating a local dictionary variable and then exposing the local
methods
| (ie localDictionary .Add).

If you are wanting a "lookup" based on a key, then you certainly need a
Dictionary. The question remains, which version of .NET are you working
with, as this decides whether you use a generic collection or not.

| It's more the theory of OO that I am struggling with I think!

You would never normally inherit from a list class in order to create a
container class. Instead you would use either Aggregation or Composition.

The choice is down to whether the containing class "owns" the items in the
list.

Composition means the contained items are owned by the containing class.
They have no context outside of the containing class; they are created,
managed and destroyed only from within the containing class.

Aggregation means that the items in the list have their own lives outside of
the containing class. The list is essntially a list of references to
instances of other classes.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jun 27 '06 #7

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

Similar topics

2
9703
by: PK | last post by:
Hello, I am looking for help on the following. I'm trying to create a custom browser toolbar button that will do a few things. One that I'm trying to do at the moment is just simply return the URL of whatever page the user is visiting. I wanted to create a Win32 application using VB.NET. If there is a better way of doing this please let...
3
1849
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that I am hoping someone can help clear up. 1. What is the difference between initializing a control in the constructor, vs the OnInit(), vs the...
7
2140
by: Robin | last post by:
In a current .Net solution (using VB.Net) has a 3 tier architecture of Web interface, Data Access Layer and Database. How do I implement business logic and class layers into this solution?
5
2269
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a collection object -- say, a dictionary. Populating that collection object with custom objects, say, Person. What I really want to see is how to...
19
4900
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom...
7
5493
by: Dale | last post by:
I have a design question. I am creating a custom collection of products. The unique key for the products is productId which is an integer. By default, IndexOf(object obj), when obj is an int, would return the value of obj because it returns the index of the item at position obj. Thoughts I had were to let the default method perform the...
1
2172
by: Abdo Haji-Ali | last post by:
Previously I used to create user controls if I wanted to use a specific set of controls in multiple pages, however I want to deploy my control in other applications so I thought of creating custom controls. Only problem is that I'm used to designing my controls in a WYSIWYG (tm) way (i.e. using the designer and writing HTML tags). The only...
3
1924
by: =?Utf-8?B?R2hpc3Rvcw==?= | last post by:
Hi all, We have a N-Tier framework and we now create a Web Site App to wotk with this architecture. I add reference from my libraries in the project and creating page and controls is very easy, using my objects. But, it's seem that I cannot create report using Crystal Report with my objects. I created classes in the app_Code folder and...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5512
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.