Head First Design Patterns by Eric Freeman, Elisabeth Freeman with Kathy Sierra, Bert Bates This errata page lists errors outstanding in the most recent printing. If you have technical questions or error reports, you can send them to booktech@oreilly.com. Please specify the printing date of your copy. This page was updated May 16, 2008. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification Confirmed errors: (code) Sample program src/headfirst/facade/hometheater/Amplifier.java; [in the jar file http://www.headfirstlabs.com/books/hfdp/hfdp.jar] public void setTuner(Tuner tuner) { System.out.println(description + " setting tuner to " + dvd); this.tuner = tuner; } should be: public void setTuner(Tuner tuner) { System.out.println(description + " setting tuner to " + tuner); this.tuner = tuner; } That is, 'dvd' should be 'tuner' (code) Sample program src/headfirst/templatemethod/barista/TeaWithHook.java; [in the jar file http://www.headfirstlabs.com/books/hfdp/hfdp.jar] The getUserInput() method contains the following line: System.out.print("Would you like milk and sugar with your coffee (y/n)? "); It should read: System.out.print("Would you like lemon with your tea (y/n)? "); (viii) 2nd paragraph, line 7; ... that encourage woman to ... should be: ... that encourage women to ... (viii) 4th paragraph; "trying to restoring" should be: "trying to restore" (ix) 3rd paragraph; runing should read: running (xxxi) Fourth through ninth numbered Item; Items are numbered 1,2,3,5,..,10 instead of 1,2,3,4,5,..,10. (xxxv) 2nd Paragraph; A space is missing between the word 'their' and the following opening parenthesis. So this: "...and the impact you've had on their(and our) lives is forever." should be: "...and the impact you've had on their (and our) lives is forever." (5) Box for RubberDuck; The string ".//" should be "//" (9) beneath the box containing the Design Principle; thruoghout should be: throughout {12} last line; Should be a.makeSound(); (13) Box for Quack class; quack) should be quack() {13} Diagram - annotation below FlyNoWay box; "And here's the implementation of all ducks that can't fly." should be "And here's the implementation for all ducks that can't fly." {14} Second sentence in the second answer iin the Q&A on page 14 should be changed to read: "As you'll see once we've got everything hooked together, we do benefit by having Duck not be an interface, and having specific ducks, like MallardDuck, inherit common properties and methods." (19) description of step 3, 3rd line; ... and Sqeak.java ... should be: ... and Squeak.java ... (21) Code; The code is improperly indented, starting with the fourth line. (21) step 5, console, last line; I'm flying with a rocket should be (in order to be consistent with the code at the bottom of the previous page): I'm flying with a rocket! (23) Master and Student dialogue; Master's second-to-last remark includes "maintaintability" it should be: maintainability (32) Middle of page, "OO Principles" box, 2nd sentence; "Favor composition over inheritence" should be "Favor composition over inheritance" {33} Crossword puzzle; There were several errors in the crossword puzzle. A corrected version can be found here - http://examples.oreilly.com/9780596007126/chapter1crossword.pdf {35} Sharpen Your Pencil Solution; There are two "C" boxes. The boxes should be A, B, C, D, E, F instead of A, B, C, C, D, E. (41) Second bullet; The closing parenthesis is missing. (52) Q&A section at bottom; Minor layout booboo: missing "There are no Dumb Questions" heading (56) UML; "CurrentConditions" should be "CurrentConditionsDisplay" (as it is in the code on p. 60). Also On page 56, the "subject" arrow from CurrentConditions (which should read CurrentConditionsDisplay) should point to the Subject interface, rather than WeatherData. (64) UML; On page 64, the "subject" arrow from GeneralDisplay should point to Observable rather than WeatherData. (65) last paragraph; notifyObserver(arg) should read: notifyObservers(arg) (78) In the Code Magnets solution, the line - Weatherdata weatherData = (WeatherData)observable; should not appear in the ForecastDisplay constructor, as it does now, but rather as the first line in the update() method. (87) 3rd answer, near middle of paragraph; would probably be wastefu). Following should be: would probably be wasteful). Following (87) last A, first sentence; remove extra "the" before "knowing the domain" ...in designing OOP systems and also a matter of the knowing the domain... should be: ...in designing OOP systems and also a matter of knowing the domain... (91) The two ConcreteDecorators; ConcereteDecoratorA and ConcereteDecoratorB should be: ConcreteDecoratorA and ConcreteDecoratorB (91) bottom left bullet text; "The ConcreteDecorator has an instance variable for the thing it decorate.. should be: "The ConcreteDecorator has an instance variable for the thing it decorates." (94), in the first paragraph, the word "lotte" should be: "latte" (96) Third annotation down on Espresso, second sentence; "Now that we don't need to worry about ..." should read just "We don't need to worry about ..." (96) Annotation at the bottom of the page; "You can create the other three Beverage classes (DarkRoast, Decaf, Esperesso) in exactly the same way. should read: "You can create the other two Beverage classes (DarkRoast and Decaf) in exactly the same way. (98) Starred annotation under the code; We're going to see a much better way of creating decorated objects when we cover the Factory and Builder Design Patterns. add to the existing annotation: Please note that the Builder Pattern is covered in the Appendix. (99) Question 1; "specfic" should be: "specific" (99) second Q paragraph; At the end of the second Question paragraph, it says "which means it would not including Whip in the order." That should be "include" instead of "including." (99) Last Question; The second sentence says "Say, I wanted my getDecription..." it should say: "Say, I wanted my getDescription..." (99) Last Answer; The last sentence says "Note that getDecription..." it should say: "Note that getDescription..." (106) 1st box; public float cost(){ should be: public double cost(){ (106) in the bottom solution box at the very top; "double mocha soy lotte with whip" should be: "double mocha soy latte with whip" {107} getSize method of Soy class; public getSize() { SHOULD BE: public int getSize() { (109) last line; embarrasing -> embarrassing (113) last line in highlighted block of code.; pizza = new eggiePizza(); should be: pizza = new VeggiePizza(); (114) last 3rd line in last paragraph; a client of that object. Any time it needs a pizzam it asks should be: a client of that object. Any time it needs a pizza it asks (115) bottom right, answer to last question; "But remember it also has the disadvanage..." should be: "But remember it also has the disadvantage..." (117) Bottom "Just another reminder:.." Second line; "write a class the implements ... should be "write a class that implements ... (119) third line in the two listings; line 3: There should be "nyStore.orderPizza" instead of "nyStore.order" line 6: There should be "chicagoStore.orderPizza" instead of "chicagoStore.order" {120} last line in code example; abstract createPizza(String type); should be: abstract Pizza createPizza(String type); (121) Second paragraph; Erroneous space after first "thick". (130) black output window at the bottom; "Grated Regiano cheese" should be: "Grated Reggiano Cheese" [in order to match the code shown on page 129] (134) Last paragraph; The last sentence should start with 'They say "decide"' (144) Last paragraph; "different set that needs to shipped..." should be "different set that needs to be shipped..." (145), in the California group; the seafood should be "Calamari", not "Camari" {148} UML drawing of classes at the bottom of the page; "Mozzarella" class name should be "MozzarellaCheese" (to match p. 145) (150 & 151) last method; Wrong way double-quotes (159) 2nd paragraph, right column (Abstract Factory); "...because I am used to create entire families..." should read: "...because I am used to creating entire families..." (160) text floating in bottom-middle of diagram; "Subclasses are instaniated by the Factory Methods." It should be "Subclasses are instantiated by the Factory Methods." (162) Abstract Factory Card; depedent should be: dependent (173), floating "a" inside "Watch it" box on the top right of the page: "you'll see a it has a few issues later in the chapter". It should be "you'll see it has a few issues later in the chapter" (175) fill method; "fill" is rendered improperly (with a hard-to-read font) {179} "Bet the JVM" code example; code example; ChocolateBoiler boiler = ChocolateBoiler.getInstance(); fill(); boil(); drain(); should be: ChocolateBoiler boiler = ChocolateBoiler.getInstance(); boiler.fill(); boiler.boil(); boiler.drain(); (204, Text above the black box on the bottom-right of the page: "Here, create a command and pass it to the receiver." it should be : "Here, create a command and pass the receiver to it." (207), in the text pointing to the Command interface, the word should be "perform", not "preform" (208) Second paragraph, Sue's statement; Sue's last sentence ends with a colon, but no example follows it. After the colon at the end of Sue's statement, add: "onCommands[0] = onCommand; offCommands[0] = offCommand; and so on for each of the seven command slots." (209) swapped letters "ie" in "reciever", bottom right of the page: "(3) In the execute() method actions are invoked on the reciever." It should be: "(3) In the execute() method actions are invoked on the receiver." (212) first paragraph; "Home Automation of Bust" should be "Home Automation or Bust" {223} RemoteLoader output window; The output in the window on page 223 does not match the code on page 222. Code has remoteControl.setCommand(0, ceilingFanMedium, ceilingFanOff); remoteControl.setCommand(1, ceilingFanHigh, ceilingFanOff); The output window has: [slot 0] headfirst.command.undo.NoCommand headfirst.command.undo.NoCommand [slot 1] headfirst.command.undo.CeilingFanMediumCommand headfirst.command.undo.CeilingFanOffCommand [slot 2] headfirst.command.undo.CeilingFanHighCommand headfirst.command.undo.CeilingFanOffCommand but should be: [slot 0] headfirst.command.undo.CeilingFanMediumCommand headfirst.command.undo.CeilingFanOffCommand [slot 1] headfirst.command.undo.CeilingFanHighCommand headfirst.command.undo.CeilingFanOffCommand [slot 2] headfirst.command.undo.NoCommand headfirst.command.undo.NoCommand (230) 1st bullet point; "The Command Pattern decouples an object, making a request from the one that knows how to perform it." remove comma (230) 5th bullet point; "excute()" should be "execute()" [233] undo() definition of top exercise; The boxed text reads: "for (int i = 0; i < commands.length; i++) { commands[i].undo(); }" The commands need to be undone in *reverse* order, like so: "for (int i = commands.length - 1; i >= 0; i--) { commands[i].undo(); }" (240) Test run at the bottom; Replace RemoteControlTest with DuckTestDrive and remove newlines that are not in the code: %java DuckTestDrive The Turkey says... Gobble gobble I'm flying a short distance The Duck says... Quack I'm flying The TurkeyAdapter says... Gobble gobble I'm flying a short distance I'm flying a short distance I'm flying a short distance I'm flying a short distance I'm flying a short distance (245) first paragraph; ")." should be ".)" (278) Top of page, annotation next to prepareRecipe(), 2nd sentence; "the second and forth steps are different, ..." should be "the second and fourth steps are different, ..." (292) first "handwritten" comment; "a condiments" should be "condiments" (295), bottom right of page, last paragraph: "so you can implement these as hooks rather than abstract classes," It should be: "so you can implement these as hooks rather than abstract methods," (298), third description in Who Does What? box: "Subclasses decide which concrete classes to create." It should be: "Subclasses decide which concrete classes to instantiate." (300) first "handwritten" comment; "paired" should be "pared" (308) first "Template Method" paragraph; Missing terminating period (321) bullet item #1; "...you'll need to call the getMenuItem() method ..." should be: "...you'll need to call the getMenuItems() method ..." (321) second code excerpt; Improper facing closing double-quotes (322) Sharpen your pencil box; Items are lettered A, B, C, C, D, E. Should be A, B, C, D, E, F. [328 + 330] 1st paragraph, 2nd sentence; The "getIterator()" text on pages 328 and 330 (first paragraph, both pages) should be replaced with "createIterator()" (332) last line, first column; you'llwant should read: you'll want (338) 3rd Question; "Could I implement an Iterator that can go backwards as well as backwards?" should be: "... backwards as well as forwards?" [350, 382] 6th magnet; The code position = rightNow.DAY_OF_WEEK % 2; should be: position = rightNow.get(Calendar.DAY_OF_WEEK) % 2; (354) 1st paragrah; second to the last line of paragraph: "... chefs that the time as come for us..." should be "... chefs that the time has come for us..." (365) Description for Apple Pie on the desertMenu definition; "icecream" should be "ice cream" (365) Second hand-written comment from the top; Text states: "We also need two top level menu now that we'll name allMenus." Corrected Version: "We also need a top level menu that we'll name all Menus." (374) Description for Apple Pie on the menu printout (in two places); "icecream" should be "ice cream" (378), 11 down: Hashtable and ArrayList both implement this interface. Should be: ArrayList implements this interface. (379) Who Does What?; Replace the text "State Pattern" at the top left of the diagram with "Strategy Pattern", and replace the description on the bottom right of the page, "Allows an object to change its behavior when some state changes" with "Encapsulates interchangeable behaviors and uses delegation to decide which one to use." (381) Sharpen your pencil solution box; Items are lettered A, B, C, C, D, E. Should be A, B, C, D, E, F. (392) first sentence; A comma is missing after "methodology". (396) Sharpen your pencil box; Items are lettered A, B, C, C, D, E. Should be A, B, C, D, E, F. (397), repeated "this" in second to last sentence by Joe: "I wonder if this will this make it easier to add new states?" It should be: "I wonder if this will make it easier to add new states?" (425) Sharpen your pencil box; Items are lettered A, B, C, C, D, E. Should be A, B, C, D, E, F. [428] Top (Who does What); The solutions for Template Method and Strategy are wrong; Template Method should point to the solution that Strategy is pointing to (i.e., the solution beginning, "Subclasses decide...") and Strategy should point to the solution that Template Method is pointing to (i.e., the solution beginning, "Encapsulate interchangeable behaviors..."). The solution for State is correct. (431) code; Improper facing double-quotes (445) Last "hand-written" note on bottom of page; The word "rmiregistery" should be "rmiregistry". {446} Code Up Close, 1st "callout"; Book says: "The client always uses the remote implementation as the type of the service." Should say: "The client always uses the remote interface as the type of the service." {456} Code execution windows at the bottom of the page; java GumballMachine santafe.mightgumball.com 100 should be: java GumballMachineTestDrive santafe.mightgumball.com 100 {457} Code execution window; java GumballMonitor should be: java GumballMonitorTestDrive {507} System.out.println() line in code; The message text in the System.out.println() statement does not match the output in the window below. Code has "The ducks quacked times". The output window has " quacks were counted". This error also occurs in several other downstream pages, 510 and 514 at least. (521) Step 18; Second sentence should read "Let's update the simulator and give it a try:" not "...give it try:" (526) bottom paragraph, first column; "applications" should be "application's" (527) second to last stanza in left column; "repititious" should be "repetitious" (557) 1st paragraph, 2nd to last sentence; minor typo: "and displayed in a seb browser." should be "and displayed in a web browser." {591} bottom right answer on the page; remove the sentence: "It's a subtle distinction, especially when you consider the structural similarities between Decorator (a structural pattern) and Proxy (a behavioral pattern)." (620) repetition production; Improper facing single quote to the right of the left parenthesis.