I have a superinterface that several different abstract classes implement: Coverage.This is for insurance rating. There are several types of different coverage, and those coverages might vary by state. The type of coverage is an abstract class, and then the concrete implementations depend on the state where whoever buys it lives (several states generally share one of these concrete implementers).Basically, we havepublic interface Coverage {/*...*/}public abstract class Pip implements Coverage {/*...*/}public final class FLPip extends Pip {/*...*/}and then we have :public class quote {    final List<Coverage> coverages;    // ...}I'm thinking it would be good to have it so that adding duplicates of any of the direct implementers of Coverage would throw an error.I mean, I could do something like this:abstract class Coverage {/*...*/}abstract class Pip extends Coverage {/*...*/}final class FLPip extends Pip {/*...*/}class Quote {    // ...    private final PriorityQueue<Coverage> coverages;    private final HashSet<Class> coverageTypes;    // ...    public void addCoverage(Coverage coverage) {        Class c = coverage.getClass();        while(c.getSuperclass() != Coverage.class)            c = c.getSuperclass();        if (coverageTypes.contains(c))            throw new IllegalArgumentException();        coverageTypes.add(c);        coverages.add(coverage);    }    public void removeCoverage(Coverage coverage) {        Class c = coverage.getClass();        while(c.getSuperclass() != Coverage.class)            c = c.getSuperclass();        coverageTypes.remove(c);        coverages.remove(coverage);    }    // ...}but this seems very hacky and prone to error / extensibility problems, and like I'm missing something here. Any ideas on a better pattern to use?
Design pattern for data structure that contains at most one item of each type
design;object oriented design