I hope this won't sound like a stupid question.
I have a class A and a class B. Now the only thing B has is a String ID. Now I can have multiple objects A that each can have 0 or more objects of type B. These are contained in a HashMap(ID,someData) each class A has.
What I want to do is each time I add a new ID in class A to check whether there already is a on object of Type B with the same ID in any of the other class A objects I have, and if not, create a new B object.
Hope this makes sense. If what I ask is wrong is some way, please be kind enough to explain how is this a bad practice or conceptualy wrong.
Thanks a lot.
EDIT:To be more clear,in my case, it is not desireable to share the HashMap(ID,someData) for all my objects as for example let's say A is a Course class,Or Catalogue, or Bank etc. Each A class may share some students/clients but each A class may contain different class B objects.