VJS
VJS

Reputation: 2951

Java Enum type naming convention

What is the best practice of naming convention of enum

public enum SystemTypeEnum {

    RRD, FFR, DDE
}

Currently the name is SystemTypeEnum. Is this ok or we should have name as SystemType

Would like to know best practice.

Upvotes: 0

Views: 2486

Answers (2)

Zabuzard
Zabuzard

Reputation: 25903

Outcome

This is a highly opinion based topic, so I will try to keep this unbiased.

There are different standards and opinions and there is no very clear outcome to the discussion.

To my knowledge the most commonly used style is to not have a suffix or prefix.


Arguments

The discussion typically also includes pre- or suffixes for abstract classes and interfaces, not only enums. Also frequently seen are prefixes like E, A, I instead of suffix.

Some argue it does not add any useful additional information to the name and only clutters it. Some say it should not matter whether it is, lets say, and interface or a class. Some say it is the job of the IDE and not the name to indicate the type, for example with colors and icons. But there are also opinions in favor of that naming standard.


Style guidelines

A widely adopted style guideline is Googles style, quoting:

In Google Style, special prefixes or suffixes are not used. For example, these names are not Google Style: name_, mName, s_name and kName.

Another style that is commonly referred to is the style used in the JDK by the Java developers themselves, they also do not use a prefix or suffix.

But again, those are just some styles, there are also others.

Upvotes: 0

Mark Bramnik
Mark Bramnik

Reputation: 42471

Disclaimer: I realize that my Answer can be considered opinionated, so my answer reflects my own experience.

I think it's better to rename to SystemType It's clear that its enum, all modern IDE show that. Following this logic, if you have, for example, interface

interface Calculator {
   int plus(int a, int b);
   int minus(int a, int b);
}

It should be renamed to CalculatorInterface - sounds weird, right?

Another example:

class Person {
   String name;
   int age;
}

Do you think its a good idea to rename it to PersonClass only because of its a class?

Bottom line, as I said, you can rely on IDE here - it will provide a visual hint for you for what it is.

Upvotes: 1

Related Questions