• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Conventions for Naming Swing Instances and Interfaces?

 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic