Maintaining a two way relationship between classes

前端 未结 6 600
萌比男神i
萌比男神i 2021-02-02 00:34

It is pretty common, especially in applications with an ORM, to have a two way mapping between classes. Like this:

public class Product
{
    private List

        
6条回答
  •  遥遥无期
    2021-02-02 01:33

    I am just now working on a problem similar to this and I am using #3 in LBushkin's answer.

    I have a data storage object with lists for all of my data classes. The data classes have ids in them for references to the other classes and I call back to the data storage class to get the reference item.

    I have found this really useful because I need to be able to filter the data and that is done when requesting the data from the data storage.

提交回复
热议问题