我只会有一个名为的类Band
和一个用于所有乐队的容器类BandRegister
。Band 将持有一个Set
代表十年的值,这些值使用以下方法相加associateWithDecate(int decade)
:
班级乐队注册:
Map<Integer, Set<Band>) decadeMap = new HahMap...
public addBand(band);
{
//define logic for adding the decade and band to decadeMap
}
班级乐队:
Set<Integer> decades = ...
public associateWithDecate(int decade)
{
//add decade to decades if not already included
}
在主要:
BandRegister breg = new BandRegister();
Band stones = new Band("Rolling Stones");
stones.associateWithDecate(60);
stones.associateWithDecate(70);
stones.associateWithDecate(70);
stones.associateWithDecate(90);
stones.associateWithDecate(0);
stones.associateWithDecate(10);
breg.addband(stones);
这样,您可以获得每个乐队的十年列表,并且在注册表中您可以获得每个十年的乐队列表