• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to name a method like addBooks According to the Java Naming Standard  RSS feed

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to name a method like addBooks According to the Java Naming Standard

Is it like



Varuna
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the method add books to something? Then public void addBooks is correct.

You would probably pass a List<Book> or Book[] array as a parameter, so you end up withor
 
Varuna Seneviratna
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes This add books and also I want to know how to name this method according to Java Bean naming standard


Varuna
 
Sheriff
Posts: 21137
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Bean naming standard does not have any support for methods except the following:
- getXxx and setXxx, where xxx is your property
- addXxxListener and removeXxxListener, for adding and removing XxxListener instances
 
Varuna Seneviratna
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct Rob I was confused when I referred the Study Guide for SCJP of Kathy and Bert it mentions naming conventions only for set and get methods for Java Beans.Then what came into my mind was what is the naming standard for methods that are not setting or returning values.According to what I get Java Beans does not have methods other than for setting or returning values.Am I correct?


Varuna
 
Rob Spoor
Sheriff
Posts: 21137
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well there's the adding and removing of event listeners I mentioned, but for the rest no.

Still, addBook(Book book), removeBook(Book book), addBooks(Book[] books), addBooks(Collection<Book> books), removeBooks(Book[] books) and removeBooks(Collection<Book> books) are perfect names - as long as they do what the say they do
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd disagree slightly with Rob and Campbell. If you are adding all of the elements of one collection to the contents of another collection then I would follow the naming used in the Collection interface. i.e. use addAllBooks(List<Book> books) instead of addBooks(List<Book> books).


[ October 17, 2008: Message edited by: Paul Beckett ]
 
Varuna Seneviratna
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a document that I can refer about Java Bean naming standard

Varuna
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I won't disagree about "addAllBooks."
 
Rob Spoor
Sheriff
Posts: 21137
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul has a point, but I'm lazy and that's three extra characters each time
 
Bartender
Posts: 9444
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Varuna Seneviratna:
Is there a document that I can refer about Java Bean naming standard


JavaBeans API Specifications
Code Conventions for the Java Language
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
Paul has a point, but I'm lazy and that's three extra characters each time
He has "Campbell" in his name; he's bound to be right.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!