Talk:Tell, don't ask

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
Line 4: Line 4:
  
 
''Does anyone know of a good paper describing this maxim? --[[User:Warwick Irwin|Wal]] 03:56, 20 August 2008 (UTC)''
 
''Does anyone know of a good paper describing this maxim? --[[User:Warwick Irwin|Wal]] 03:56, 20 August 2008 (UTC)''
 +
 +
Doesn't the application of this principal really depend on what you are modeling? To use the example of the Human/Lung, if you have a model where you have many different mammals which each breathe slightly differently, but all have lungs. You could create several Lung subclasses, say HumanLung, SheepLung and HorseLung, along with each of which has an associated mammal class. The implementations of each of the Lung classes may only differ slightly, possibly only providing an implementation of a single method. Now, if you disobey this principle, and have each mammal ask, not tell, and provide it's own breathing implementation then they can all use the standard Lung class. This removes the need for three additional classes and requires the same amount of code. Isn't that the cleaner implementation? ~ [[User:Ryan Mallon|Ryan]]

Revision as of 19:53, 21 August 2008

added explanations of "Tell, don't ask" principle, might need to simplify my explanation. --Jojo 01:18, 24 July 2008 (UTC)

added a concrete example of "Tell, don't ask" principle --Jojo 02:25, 20 August 2008 (UTC)

Does anyone know of a good paper describing this maxim? --Wal 03:56, 20 August 2008 (UTC)

Doesn't the application of this principal really depend on what you are modeling? To use the example of the Human/Lung, if you have a model where you have many different mammals which each breathe slightly differently, but all have lungs. You could create several Lung subclasses, say HumanLung, SheepLung and HorseLung, along with each of which has an associated mammal class. The implementations of each of the Lung classes may only differ slightly, possibly only providing an implementation of a single method. Now, if you disobey this principle, and have each mammal ask, not tell, and provide it's own breathing implementation then they can all use the standard Lung class. This removes the need for three additional classes and requires the same amount of code. Isn't that the cleaner implementation? ~ Ryan

Personal tools