Thursday, January 31, 2008

Tell, Don't Ask

Procedural code gets information then makes decisions. Object-oriented code tells objects to do things.
— Alec Sharp

Programmers should avoid writing code that looks like:


colloquially known as a “Train Wreck”. This is bad because this
one line depends on the interfaces and implied structure of three
different objects

The solution is described by the heuristic "Tell, Don't Ask" , so we rewrite our
example as:


and let the implementation of the dog decide what this means.

1 comment:

Pawan said...

I like your tell, don't ask funda .. nice one, programmer should learn to wirte leading program rather than asking programs. sounds good.