I'm doing a java project. My main structure contains 2 lists with elements of type A the other type B. B itself contains a list of objects which may contain elements of A.
It must be that when an element from list of A is removed it must be removed from all subelements in list B. also if an possible member of list A is added to a B it should also be added to A. And also I need some way to find the parent objects containing an A.
So far I have a "working" implementation - using lots of loops. I am wondering - can you suggest patterns that will help me in this task?
I think my main issue is boils down to that i have objects A that have multiple parents. And when I add/remove from one parent I need to adjust some other parents.
I can't help but believe such a problem is solved already.
to clarify: I have a main
List<A> , and each
B contains a
When a A is removed from the main list it must be removed from all B. But not when it is removed from a B. It's essential that all A used in the application are present in the main list.