Many-to-many relationship in oop

后端 未结 7 761
北恋
北恋 2021-02-04 15:53

what is best way to model many-to-many relationship?

lets say we have a two classes , Team and Player

  • any given P
7条回答
  •  感情败类
    2021-02-04 16:25

    The answer from Will is correct. However, to deal with syncing, I would probably start with ObservableCollection. Have one side of the relationship be the "master" which keeps track of adds / removes on the other side and deals with syncing.

    However, be aware that if one object is subscribing to events on the other that this is a strong reference that will prevent garbage collection. Most likely they will be leaving scope at the same time so this is a non-issue but it is something to be aware of.

提交回复
热议问题