Data Pull vs. Push OOP Approach

Bunkai.Satori picture Bunkai.Satori · Apr 26, 2011 · Viewed 26k times · Source

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 pull the necessary data from another objects.

Is there anything like a standard in OOP design, that I should prefer data pull by objects, versus data push into objects?

Can anyone experienced advise, whether one approach is better over the other from longer term viewpoint, or when the OOP structure/framework/diagram gets more complex?

Answer

Kamil Tomšík picture Kamil Tomšík · May 2, 2011

According to tell dont ask, push is better - or more OO. You don't want to query object for data so you can do something, you want object to do it, because he's the one who knows his data.

Related article about evil getters