Add content: Tell Don't Ask principle in Software Design roadmap
Added comprehensive explanation of Tell Don't Ask principle with examples. Fixed @article tag capitalization. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
e003b1ed61
commit
dc60c4eb00
1 file changed
+28
-1
+28
-1
@@ -1 +1,28 @@
|
||||
# Tell, don't ask
|
||||
# Tell, Don’t Ask
|
||||
|
||||
The Tell, Don’t Ask principle emphasizes that objects should be told what to do rather than being queried for their state and having decisions made externally. This promotes encapsulation and reduces coupling by keeping logic within the objects that own the data.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
- Instead of pulling data out of objects to make decisions, push the behavior into the object itself.
|
||||
- Objects should be responsible for their own logic and state management.
|
||||
|
||||
Asking style (bad):
|
||||
|
||||
```
|
||||
if (user.profile.isComplete()) {
|
||||
// allow checkout
|
||||
}
|
||||
```
|
||||
|
||||
Telling style (good):
|
||||
|
||||
```
|
||||
if (user.canCheckout()) {
|
||||
// allow checkout
|
||||
}
|
||||
```
|
||||
|
||||
Learn more from the following resources:
|
||||
|
||||
- [@article@Tell, Don't Ask](https://martinfowler.com/bliki/TellDontAsk.html)
|
||||
Reference in new issue
Block a user