What's a "what"? How do you define "how"?
A "what" is a delegation to another method with a MeaningfulName. A "how" is a method that does one thing.
Example - before
moveRoom: aRectangle couch x: (aRectangle origin x + couch offset x) y: (aRectangle origin y + couch offset y). chair x: (aRectangle origin x + chair offset x) y: (aRectangle origin y + chair offset y). bookshelf x: (aRectangle origin x + bookshelf offset x) y: (aRectangle origin y + bookshelf offset y).after
moveRoom: aRectangle | origin | origin := aRectangle origin. self moveCouch: origin. self moveChair: origin. self moveBookshelf: origin.SeparateTheWhatFromTheHow is an approximation. If a method doesn't read "what-what-what..." or "how", but there is no obvious fix, leave it alone.
I am having trouble following this psuedocode. What is Origin? Why is everything a rectangle? What is moveX (where X = Chair, etc.) Is it a method or attribute?
This isn't pseduocode, it's code, smalltalk code. I'm no smalltalker, but as best I know, "| origin |" declares a variable local to the method, and the "moveX" things are selectors (like keyword arguments) for methods. The example isn't complete because it doesn't show how the "couch x: (aRectangle blah blah blah" stuff has been moved into other methods of whatever class moveRoom: belongs to.
HaveThisPattern: Alternate approach to the "what vs how" question is an old ModularProgramming maxim:
Isn't this similar to the old separation of mechanism and policy?
SeparateTheWhatFromTheHow is similar to ComposedMethod. See also ShortMethods and IntentionNotAlgorithm.
This page mirrored in WikiPagesAboutRefactoring as of July 17, 2004