Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handle and Request Method Naming Conventions

 
Camden Reslink
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've already made my way through an introductory Java-based college course, and Head First Java. I'm now working my way through Head First Design Patterns, and the first one is the Strategy Pattern.

A Request method in the Superclass of a bunch of concrete Subclasses delegates the method call to a Handler method in the Interface for a group of classes that are the implementation for that request method. I don't know if that made any sense, or I'm just speaking Javanese. Anyway, I've written a few silly sample programs that show how the Strategy pattern works and there is only one thing I am unsure of.

Are there any naming conventions for the handler and request methods? I've seen them named the same thing, but I feel like this could be confusing, but at the same time they are really just doing the same thing.

The book example looks like this:


Any thoughts?
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't start identifier names with _ or $, except as described in the Java™ Tutorials about package names.
 
Camden Reslink
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

Don't start identifier names with _ or $, except as described in the Java™ Tutorials about package names.


Really? My instructor has been having us name instance variables with an underscore at the beginning. I'll start using this.instanceVarName instead. Any idea about my initial question?
 
Ed Connery
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Camden Reslink wrote:
Really? My instructor has been having us name instance variables with an underscore at the beginning.
You might want to take a look at the Style Guide thread that's on the first page now, and consider that your instructor has given you a style guide to follow in your class. You and I (and Campbell) may not agree with that style, but for the duration of the class you may need to follow it. You may also look at the Java Programming Style Guide and try to use its conventions when your instructor does not object.
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both those style guides, and (if I remember correctly) the Java™ Tutorials tell you to start all names (except possibly package names) with a letter. Not _ or $.
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And don't routinely include "instance" in an identifier. That sounds like Hungarian Notation (so-called) which most people deprecate, although Joel Spolsky has a good justification for it in some cases.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic