views:

16

answers:

1

Hi, I have an object can be compose by components but each components has a type and should be unique :

Class Client{
  Set<IComposite> elements  
}
interface IComposite{
  String getType();
}
class Status implements IComposite{
  String getType(){return "status"}
}
class ClientDates implements IComposite{
  String getType(){return "clientdate"}
}    

So I suppose I could encapsulate the collection but each element should be unique, so only 1 status, only one clentdate, but perhaps can I create a new Composite class that could be multiple.

An idea how to design that ?

Thanks a lot

A: 

you may have a Dictionary as the collection of your elements with their unique id(type in your case) as the dictionary's key. while adding the element you can check if the element is exist in the dictionary. So you can keep the collection with unique elements.

Arseny
right. I forgot Dictionary ! Aïe