posted 23 years ago
The example seems very puzzling. I can't understand why you are trying to create all those Elements and Sets as member variables of every Element. If you just want to try out extending existing classes, consider the following version of your code:
I also have a few comments...
1. If you actually need a set, then I recommend looking at Sets as provided by the Collections API, in particular the Set interface and the HashSet class.
2. Your set implementation has an apparent "gotcha". Because you use Vector.contains() it will only reject duplicates if the actual object is the same, but not if you try to add a different object with the same name, which is probably what you want. The way round this is to provide an equals(Object) method in your Element class.
3. I have removed your "removeElement" as it was completely redundant - calling the one from Vector works fine.