Hope this doesn't seem like a silly question.
I have class A and class B. Now the only thing that has B is String ID. Now I can have several objects A, each of which can have 0 or more objects of type B. They are contained in the HashMap (ID, someData), which each class A has.
What I want to do is every time I add a new identifier to class A to check if there is already an on object of type B with the same identifier in any of the other objects of class A that I have, and if no, create a new object B.
Hope this makes sense. If what I ask is wrong anyway, please be kind enough to explain how this is bad practice or conceptually wrong.
Many thanks.
EDIT: to be more clear, in my case it is not advisable to share a HashMap (ID, someData) for all my objects, for example, let them say that A is a course class, or a directory or a bank, etc. Each Class can be shared by some students / clients, but each Class A can contain different objects of class B.
source share