Home > Backend Development > PHP Tutorial > Tell Don&#t Ask principle explained

Tell Don&#t Ask principle explained

Barbara Streisand
Release: 2024-12-31 19:21:09
Original
623 people have browsed it

Tell Don

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.

The above is the detailed content of Tell Don&#t Ask principle explained. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template