Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Conventions for Naming Swing Instances and Interfaces?

 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am well familiar with the Sun java coding conventions, but I wonder if there is such a thing for naming the GUI variables and the interfaces.
For example, if I have a "Book" button, how should it look like:
1. JButton jbuttonBook = new JButton("Book");
2. JButton bookButton = new JButton("Book");
3. JButton jbBook = new JButton("Book");
How about the names of the interfaces and the classes that implement them:
1. Data / DataImpl
2. DataInterface / DataImpl
3. Data / SomethingElse
Any conventions?
Thanks,
Eugene Kononov.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eugene Kononov:
1. JButton jbuttonBook = new JButton("Book");
2. JButton bookButton = new JButton("Book");
3. JButton jbBook = new JButton("Book");

I would write like:

Originally posted by Eugene Kononov:
How about the names of the interfaces and the classes that implement them:
1. Data / DataImpl
2. DataInterface / DataImpl
3. Data / SomethingElse

I have IData as the name of the interface and
DataRemote is the class implementing IData
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eugene Kononov:
I am well familiar with the Sun java coding conventions, but I wonder if there is such a thing for naming the GUI variables and the interfaces.
For example, if I have a "Book" button, how should it look like:
1. JButton jbuttonBook = new JButton("Book");
2. JButton bookButton = new JButton("Book");
3. JButton jbBook = new JButton("Book");
How about the names of the interfaces and the classes that implement them:
1. Data / DataImpl
2. DataInterface / DataImpl
3. Data / SomethingElse
Any conventions?
Thanks,
Eugene Kononov.

For button I had


and for my Interface I had
DataAccess which was my interface and
RemoteDataAccess and LocalDataAccess as my implementing classes.
If you look at the classes in the SDK API SDocumentation, you will not see any classes with an Impl at the end, even though it implements and interface.
Mark
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the subject of naming conventions, is it a good idea to name classes/interfaces after the design pattern they represent?
For example:
ConnectionFactory
DataAdapter
ActionCommand
DispatcherManager
On one hand, it makes it easier to read code. One the other hand, shouldn't the class hide the details of implementation? Which reason prevails?
Thanks,
Eugene Kononov.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would name the classes/interfaces with the design patterns they represent. It helps me understand the code even if I wrote the code in the first place!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did too. I had ConnectionFactoryEngine, which was the Server Engine and the Factory for Connections.
I also had the DataAccessFacade, DataAccessFactory.
I would say to look at the API docs, and see how they name classes that match design patterns. They have Factory classes, Iterator, Observable, Observer, etc.
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic