0

I am working at a java-project were every enum has a postfix 'Type', e.g. 'PassengerType.java'. Is this an appropriate naming convention, or should it better be 'Passenger.java'? The problem is that there is already a class 'Passenger.java' with a field PassengerType, denoting the 'type' of passenger. What naming scheme would you suggest?

Mike Zboray
  • 37,291
  • 3
  • 75
  • 108
Funkwecker
  • 1,004
  • 11
  • 20

2 Answers2

0
public enum Type {}
//...
public class Passenger {
    private Long id;
    private Type type;
    //...
}

I don't think there is a problem with this naming convention at all. The only think that would bother me is if the field type was actually called passengerType (same as passengerId instead of id). The fields are already defined in a class called Passenger so no need to prefix them with passenger.

The Java tutorial examples have no postfix: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

Also on SO: Coding Conventions - Naming Enums

Community
  • 1
  • 1
JamesB
  • 7,314
  • 1
  • 19
  • 20
0

I am maintaining a large project and I have to admit something. I often times do not know if an enumeration for something already exists. They probably should all be in one package somewhere (I am working on that). But I wish there were a standard in this project I am dealing with that used a postfix of Type or even Enum. I know that this is 100% against the "rules". But it is also something that is necessary on a per project basis. Even if just temporary before refactoring to a package for enums. In eclipse it would be very nice to type ctrl-shit-T and be able to find 'PassengerType' and know that this is THE enumeration. The problem of course is that in my large project I need a Passenger enum but there may already be a Commuter or Patron enum that serves the purpose of the enum I am about to create.

Guidelines are just that, guidelines. not rules. Sun called them guidelines for a reason. Because the guidelines can be violated on occasion and it is acceptable!