aspose file tools*
The moose likes Beginning Java and the fly likes Handle and Request Method Naming Conventions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Handle and Request Method Naming Conventions" Watch "Handle and Request Method Naming Conventions" New topic
Author

Handle and Request Method Naming Conventions

Camden Reslink
Greenhorn

Joined: Dec 09, 2010
Posts: 2
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?


Just trying my best to learn the best OO-Practices.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
Welcome to the Ranch

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

Joined: Dec 09, 2010
Posts: 2
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

Joined: Mar 11, 2010
Posts: 70
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

Joined: Oct 13, 2005
Posts: 39885
    
  28
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

Joined: Oct 13, 2005
Posts: 39885
    
  28
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.
 
jQuery in Action, 2nd edition
 
subject: Handle and Request Method Naming Conventions