This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes upper case vaiolates OO abstaction - why Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "upper case vaiolates OO abstaction - why" Watch "upper case vaiolates OO abstaction - why" New topic
Author

upper case vaiolates OO abstaction - why

Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
In the Style Guide is the following:
"3.3 - All Other Identifiers
All other identifiers, including (but not limited to) attributes, variables, methods and parameters will use this default naming convention. This includes
final identifiers (using all upper case, as traditionally done in C, is a violation of OO abstraction)...."
I don't understand why using upper case for final (constant) identifiers is a violation of OO abstraction. Isn't it a naming convention? That is, wouldn't I be violating a naming convention if upper case was not allowed? Is this covered in Just Java? I don't have the book yet, it's on its way.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
"using all upper case, as traditionally done in C, is a violation of OO abstraction"

By using upper case for final identifiers, you are assuming that that particular variable will be a constant forever. Now, while that is probably true for pi (3.14...), most of the time you cannot guarantee that what is declared as final in your program will always remain a constant. By using the default naming convention, your program will be more flexible. Who wants to change hundreds of identifier names in an application just because the constant is now variable?

By keeping the identifiers the same, you are abstracting the thing it contains. There are plenty of times where we shouldn't care what the reference is referring to - an int or an Integer, an array or an ArrayList, a constant or a variable.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
Marilyn,
I had to read your reply a few times before it sunk in. I understand now.
I've actually been faced with this problem in the real world a couple of times. But, a different naming convention for constants (use "Literal" in name, make all upper case, etc.) has been the only standard I've ever been taught or told to use.
Using the same naming convention for constants as variables makes sense when taking into account that future life of the code.
Thanks, richard
Bruce Wingate
Ranch Hand

Joined: Feb 16, 2001
Posts: 32
So, if the constant is constant, like PI, Gravity on earth, the speed of light in a vacuum, then its OK to capitalize it, but if the constant is line length, page length, or number of connections allowed, then its not really a constant, so it should not be in all caps. I can deal with something like that.
I'm still trying to get myself out of Hungarian notation and inital caps for functions.
I'm rather pleasantly surprised with the style guide. I've developed my own style over these many years of coding, and the only real eye-opener was spaces around identifiers, but it makes sense when you need to search for a variable.
ryan burgdorfer
Ranch Hand

Joined: Jan 24, 2001
Posts: 219
Bruce,
I don't think they want you to EVER make a constant identifier in all caps...even if it is a "true" constant.
Am I correct, Nitpickers?


<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
That's right, Ryan. The style guide makes no allowances for constants ever being in all caps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: upper case vaiolates OO abstaction - why