Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • An alternative would be to have the call be named "ensureCarOn()". Caller doesn't have to check whether it is already on, just knows that, after that cal, the car is on. (or some Exception gets thrown) Commented Jan 24, 2019 at 2:25
  • 1
    True, the caller may not need to ensure the car is on, but by providing the public method you pre-plan for a use where the caller may need to know if its on. Say if the caller has other functions like lock doors that needs to know because the original car class didn't have power doors Commented Jan 24, 2019 at 2:29
  • Tell don't Ask Caller should just "tell* the car to lock the doors. Not Ask "how many doors do you have?", "Are they power", etc... Commented Jan 24, 2019 at 5:24
  • No, i meant if the caller was an extension of the car class and had a lock doors function it might call isCarOn to decide if it needs to fire its own lockDoors, not ask car about those features, it owns the features and only asks the car if it is on so it can decide for itself what to do. Commented Jan 24, 2019 at 5:29
  • Ok. But then isCarOn() should be protected, not public. As soon as you add it to the public API you are pretty much stuck with it. Many would try to severely limit protected methods as well, though I am not on of them. Commented Jan 24, 2019 at 5:39