Many-to-many relationship in oop

后端 未结 7 750
北恋
北恋 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:04

    IMHO what you describe is the "natural" way for OO. Your XXX.getXXXList() is the interface to your classes. And for a limit number of classes that would be the right way.

    Consider there are 1000 classes that can be "interconnected". Than it may be interesting to have some ManyToManyManager to drop in an object, add another object to the related objects of an object and retrieve the list of all objects releated to another. That would be some sort of delegation vs. implementation.

    Shure if you delegate your many-to-many to another instance your object model do not reflect that many-to-many relation anymore.

提交回复
热议问题