diff --git a/src/data/roadmaps/software-design-architecture/content/tell-dont-ask@0rGdh72HjqPZa2bCbY9Gz.md b/src/data/roadmaps/software-design-architecture/content/tell-dont-ask@0rGdh72HjqPZa2bCbY9Gz.md index 72905b54a..ed7ac738d 100644 --- a/src/data/roadmaps/software-design-architecture/content/tell-dont-ask@0rGdh72HjqPZa2bCbY9Gz.md +++ b/src/data/roadmaps/software-design-architecture/content/tell-dont-ask@0rGdh72HjqPZa2bCbY9Gz.md @@ -1 +1,28 @@ -# Tell, don't ask \ No newline at end of file +# 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)