You can simplify the task by moving the "association of objects" to the selected class. Here is what I mean.
Define a class called AssociationTable. This class will maintain a list of pairs, where each pair contains a link to an object A and a link to an object B.
Each object A (and each object B) will contain a reference to the AssociationTable object. A.Add (B) will be implemented as table.add (this, b); B.Add (A) will be implemented as table.add (a, this);
Deletion will be implemented as table.delete (this, b) or table.delete (a, this)
class Pair { A a; B b; Pair(A a, B b) { this.a = a; this.b = b; }
Edit: The problem with this design is garbage collection. the table will contain references to objects, thereby suppressing their collection. In Java, you can use the WeakReference object to solve this problem. I'm sure there is something similar in the .Net world
In addition, the table can be single. I do not like singles too much. Here, a singleton will make the AB association unique in your program. This may not be desirable, but it depends on your specific needs.
Finally, (just to put things in context), this project works just like many-to-many relationships in relational databases.
source share