Guest User

Untitled

a guest
Nov 12th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public class A
  2. {
  3. public List<B> Bs { get; private set;}
  4.  
  5. public void AddB(B b)
  6. {
  7. Bs.Add(b);
  8. }
  9.  
  10. public void RemoveB(B b)
  11. {
  12. Bs.Remove(b);
  13. }
  14.  
  15. public int DoWork()
  16. {
  17. // Need details of B
  18. // Probably need to inject a service that gets B details...
  19. }
  20. }
  21.  
  22. public class B
  23. {
  24. public A A1 { get; private set; }
  25. public A A2 { get; private set; }
  26.  
  27. public B(A a1, A a2)
  28. {
  29. A1 = a1;
  30. A2 = a2;
  31. }
  32.  
  33. public void ChangeA1(A a1)
  34. {
  35. A1.RemoveB(this);
  36. A1 = a1;
  37. A1.AddB(this);
  38. }
  39.  
  40. public void ChangeA2(A a2)
  41. {
  42. A2.RemoveB(this);
  43. A2 = a2;
  44. A2.AddB(this);
  45. }
  46. }
Add Comment
Please, Sign In to add comment