- Use
SnakeCase
for directory names. - Use a singular noun or a compound noun for directory names.
- If a directory structure requires multiple words, create subdirectories.
- Use
PascalCase
for class names. - Interface names should start with an
I
followed by aPascalCase
class name. - Abstract class names should start with an
A
followed by aPascalCase
class name.
- Use
CamelCase
for class field names. - Field names should start with an underscore.
- Field names should give a clear indication of the field's purpose and of the object type it holds.
- Use
CamelCase
for method names. - Method names should be a verb or a verb phrase that describes the method's action.
- Getter methods should start with
get
, unless they are boolean, in which case they should start withis
.
- Use
CamelCase
for method parameter names. - Parameter names should give a clear indication of the parameter's purpose and of the object type it holds.
- Use
CamelCase
for variable names. - Use
UPPER_SNAKE_CASE
for static constants. - Variable names should give a clear indication of the variable's purpose and of the object type it holds.
- Use 4 spaces for indentation.
- Do not use tabs for indentation.
- Use blank lines to separate blocks of code.
- Curly brackets should be on the same line as the statement they belong to.
- Brackets should contain a single statement, unless the statement is a boolean or arithmetic expression.
- Avoid using curly brackets for single-line statements.
- Keep lines of code under 120 characters.
- Do not chain more than 2 method calls in a line.
- Do not nest more than 2 levels deep.
- Apply the single responsibility principle.
- Keep classes under 200 lines, if they are longer it is likely that they do not have a single responsibility or can be broken down into smaller classes.
- Do not use public fields, use properties instead (except for constants or the classes in the
luka.modularmap.client.config
package). - Do not use static classes, use singletons instead (except for classes in the
luka.modularmap.client.event
package). - Do not use class nesting, use composition instead.
- The order of class members should be as follows:
-
Constants
-
Fields
Use fields without the
this
keyword, unless it is not possible. -
Constructors
-
Properties
-
Methods (private, protected, public in that order)
Methods that override a parent method should be placed at the end.
-
- Apply the single responsibility principle.
- Keep methods under 20 lines, if they are longer it is likely that they do not have a single responsibility or can be broken down into smaller methods.
- Create separate methods for separate logic.
- Do not use static methods, use instance methods instead.
- Use
@Override
annotation when overriding a parent method. - Apply defensive programming.
- Apply the DRY (Don't Repeated Yourself) principle.
- Apply the DRY (Don't Repeated Yourself) principle.
- Use annotations to provide metadata about the code (e.g.
@Override
,@Nullable
,@NotNull
).
- Use
*Service
for classes that provide a service. - Use
*Repository
for classes that provide access to a data source. - Use
*Factory
for classes that create objects. - Use
*Builder
for classes that build objects. - Use
*Mapper
for classes that map objects. - Use
*Validator
for classes that validate objects. - Use
*Converter
for classes that convert objects. - Use
*Handler
for classes that handle events. - Use
*Listener
for classes that listen for events. - Use
*Manager
for classes that manage objects. - Use
*Controller
for classes that control the flow of the application.
- Single responsibility principle
- Don't repeated yourself principle
- Defensive programming