These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Collection implementation issue
PostPosted: Thu Jun 21, 2007 8:49 am 
Newbie

Joined: Thu Jun 21, 2007 8:44 am
Posts: 4
I have an object that contains a set of other objects

public class Item
{
}

public class ItemCollection : HashedSet<Item>
{
}

public class Part
{

ItemCollection itemCollection;
}

How can I specify this?

If I change :
ItemCollection itemCollection;
to
ISet<Item> itemCollection;

it works fine, but I don't want that. I want to be type safe and use the correct class.

Any ideas?


Top
 Profile  
 
 Post subject: Re: Collection implementation issue
PostPosted: Fri Jun 22, 2007 8:40 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
soundman32 wrote:
...but I don't want that. I want to be type safe and use the correct class.


I don't see any caveats from you construction. In my opinion it is always the best approach to use interface if possible. Using the ISet<...> is safe with respect to any aspect, isn't it?

Please describe what exactly your goal is?

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject: Re: Collection implementation issue
PostPosted: Fri Jun 22, 2007 12:29 pm 
Newbie

Joined: Thu Jun 21, 2007 8:44 am
Posts: 4
If I want to search my collection for a specific item (say by name) I would like to create a function in my collection class:

class ItemCollection : HashedSet<Item>
{
Item SearchByName(string name)
{
foreach(Item i in this)
if(i.Name == name)
return i;
return null;
}
}

I can't do this is all I have is ISet<Item>.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 24, 2007 2:40 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
What is the behavior when you use your collection? Did you get any exception?

Again, I think that such algorithms should rather be in the DAO layer. The domain objects should be as transparent as possible. Introducing such functionality you inject a logic to the data objects. Later when you want to have different behavior (just in one case where other applications should remain original) you will have to change the code.

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.