开发者

Which pattern to use in replacement of composite with limited number of element type?

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开发者_Python百科();
}
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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜