The Pragmatic Bookshelf | Tell, Don't Ask
That is, you should endeavor to tell objects what you want them to do; do not ask them questions about their state, make a decision, and then tell them what to do.
The problem is that, as the caller, you should not be making decisions based on the state of the called object that result in you then changing the state of the object. The logic you are implementing is probably the called object's responsibility, not yours. For you to make decisions outside the object violates its encapsulation.
Read full article from The Pragmatic Bookshelf | Tell, Don't Ask
No comments:
Post a Comment