Data Pull vs. Push OOP Approach

后端 未结 12 748
旧时难觅i
旧时难觅i 2021-01-30 02:41

When I design my system from scratch, I often face a dilemma whether my object should push information into another objects OR whether the objects should

12条回答
  •  礼貌的吻别
    2021-01-30 03:10

    I think the discussion here is kind of missing the crucial point about pulling and pushing and it is stuck on individual examples and cases.

    Pushing : The advantage of pushing is that you know your data and you know what you are pushing. No component knows (or should not know) the data better than the component who owns the data, which will theoretically imply a better design and a more robust system.

    Pulling : The only advantage I see in pulling approach is the component who pulls exactly knows when it should pull. It can initiate the conversation when it needs the data and no component knows (or should not know) when the data is needed than the component who needs it.

    My conclusion on that is: whichever the component owns the transaction, it initiates the transaction. If you are retrieving data from an API, obviously the API client will own the transaction so will do a pull. If you are broadcasting a message than the broadcaster owns the transaction so it does a push.

提交回复
热议问题