Tell Don't Ask: Why OOP Should Command Objects, Not Query Their Data
The 'Tell Don't Ask' (TDA) principle revives Alan Kay's original vision of object-oriented programming, where objects exchange messages and make their own decisions rather than exposing internal data for outsiders to manipulate. The core idea is that instead of extracting an object's data to make a decision externally, you should instruct the object to perform the action itself. This approach centralises business logic inside the owning object, meaning a rule change needs to be made in only one place rather than tracked down across multiple scattered conditionals. TDA also naturally encourages compliance with the Law of Demeter, since commanding objects eliminates the need to traverse internal structures like 'a.b.c'. The principle applies primarily to behaviour and business decisions, not to pure data-display scenarios or data-transfer objects that carry no behaviour by design.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in