aspose file tools
The moose likes Beginning Java and the fly likes I'm probably overlooking something very stupid... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "I Watch "I New topic
Author

I'm probably overlooking something very stupid...

Daniel Gagnon
Greenhorn

Joined: Aug 27, 2006
Posts: 13
Hi. I'm new to Java but not to programming. I'm re-reading the excellent Head First Design Patterns because now I know the language it was written for instead of trying to translate to another language.

I'm stuck on the first pattern. I think I understand it but I'm unsure. I copied what's in the book to play with it by my IDE (Eclipse) is giving me an error on two lines.

I compared what I wrote and what's in the book but I can't spot the difference that makes my code fail. I looked until my brain started oozing out of my ears. I'm probably overlooking something really stupid. Can some more experienced with Java than me take a look and tell me why it doesn't work ?

I put everything in a package called duckies because Eclipse tells me it's not a good idea to let everything in default. I don't think it really matters, does it ?

Thanks a lot

Dan

So the pattern is Strategy. And the code goes as follow (problematic lines in bold) :

Duck.java


FlyBehavior.java


FlyWithWings.java


FlyNoWay.java


QuackBehavior.java


Quack.java


Squeak.java


MuteQuack.java


MallardDuck.java
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

Hi,

Welcome to JavaRanch!

In Java, a constructor invocation always includes parentheses, even if the argument list is empty. Both of those lines have the same problem: a missing set of empty parentheses right before the semicolon.


[Jess in Action][AskingGoodQuestions]
Daniel Gagnon
Greenhorn

Joined: Aug 27, 2006
Posts: 13
Wow. That was a fast answer, thanks.

I feel like banging my head on a wall for missing that mistake though...

My code works now. Thank you very much
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

You implied in your first message that you read first HFDP and applied the knowledge to some other language; I assumed it might be C++, where the no-parentheses thing would be correct. Anyway, just part of the territory; glad to help!
Daniel Gagnon
Greenhorn

Joined: Aug 27, 2006
Posts: 13
Python actually. It involved understanding the concepts from HFDP, lots of Googling to figure out how people were doing it in Python and trying it out. Because of the language differences, I feel I didn't get as much as I could from the book so now that I picked Java, I'm reading it again.

I do now C++ however which might be why I got confused.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: I'm probably overlooking something very stupid...
 
Similar Threads
Polymorphism is the deebil
HFDP - Strategy Pattern
Did I make the Strategy pattern unnecessarily complicated?
head first design patterns problem
Problem with Head First Design Patterns code