The basic principle of the Tell Don't Ask principle is to prefer telling an object what to do rather than asking an object for its data and acting on this data.
The idea is to put into the object the behavior related to that object.
The object that owns a data is responsible of its own logic.
The code is therefore more coherent within the codebase and within the object itself.
Last but not least, the behavior is encapsulated in the object meaning that you can work with a minimal public interface outside of the object which makes it easier to maintain and modify.
Top comments (0)