DEV Community

thiCha
thiCha

Posted on

Tell Don't Ask principle explained

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)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay