Skip to content

Instantly share code, notes, and snippets.

@nekman
Created February 1, 2019 07:06
Show Gist options
  • Save nekman/f19269243edb417461ea28a08a3276d6 to your computer and use it in GitHub Desktop.
Save nekman/f19269243edb417461ea28a08a3276d6 to your computer and use it in GitHub Desktop.
/**
*
* Methods and member ordering (proposal).
*
*/
public class Example implements Closeable {
// 1. Public static final constants
public static final String CONSTANT = "";
// 2. Protected static final constants
protected static final int PROTECTED_CONSTANT = 1;
// 3. Protected final fields
protected final int PROTECTED_MEMBER = 1;
// 4. Private static final constants
private static final Logger LOGGER = LoggerFactory.getLogger(Example.class);
// 5. Private static constants
private static String STATIC;
// 6. Static initializers
static {
STATIC = "1";
}
// 7. private final fields
private final String finalMember;
// 8. private fields
private String nonFinalMember;
// 9. Constructor with most number of parameters
public Example(final String param) {
finalMember = param;
}
// 10. Default constructor
public Example() {
this(CONSTANT);
}
// 11. Overrides
@Override
public void close() throws IOException {
}
// 12. Public instance methods
public String getFinalMember() {
return getFinalMemberValue();
}
// 13. Protected instance methods
protected int getProtectedMember() {
return PROTECTED_MEMBER;
}
// 14. Public static methods
public static String getConstant() {
return getConstantValue();
}
// 15. Public static methods
protected static int getProtectedConstant() {
return PROTECTED_CONSTANT;
}
// 16. Private instance methods
private String getFinalMemberValue() {
return finalMember;
}
// 17. Private static methods
private static String getConstantValue() {
return CONSTANT;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment