...
- You consider doing it according to this conventions, assuming you fully understand them.
- If your common sense tells you it's not right, it probably isn't - do it your way.
- But don't leave it like that, talk about it, or even better update this page.
Mes specific conventions
Fields constants
Every time we add a new model field we should add it to the constants/PluginNameFields.java like this:
Code Block |
---|
public class PluginNameFields {
public final static String ORDER = "order";
} |
So we won't repeat those string literals over and over when accessing entities fields. We're gonna use:
Code Block |
---|
entity.getBelongsToField(PluginNameFields.ORDER); |
or even better:
Code Block |
---|
import static com.qcadoo.mes.pluginName.constants.PluginNameFields;
entity.getBelongstoField(ORDER); |
I know it's something new, and refactoring the whole system will be a horror. Let's just use it from now on, ok?
Java enums
For every enum field of a model we create, we should create corresponding Java enum in constants package.
For ex.
Code Block | ||
---|---|---|
| ||
public enum BatchNumberUniqueness {
GLOBALLY("01globally"), MANUFACTURER("02manufacturer");
private String stringValue;
private BatchNumberUniqueness(final String stringValue) {
this.stringValue = stringValue;
}
public String getStringValue() {
return stringValue;
}
public static final BatchNumberUniqueness parseString(final String string) {
if ("01globally".equals(string)) {
return GLOBALLY;
} else if ("02manufacturer".equals(string)) {
return MANUFACTURER;
} else {
throw new IllegalStateException("Couldn't parse BatchNumberUniqueness from string");
}
}
} |
Naming conventions
Naming literals:
EDIT: look at the mes specific convention about model field literals.
If the same string literal occurs more than once we extract it to a field like this:
...
Code Block |
---|
// state is either 01draft or 02accepted
if ("01draft".equals(state)) {
doSomething();
} else if ("02accepted".equals(state)) {
doSomethingDifferent();
} else {
throw new IllegalStateException("state is neither 01draft nor 02accepted");
}
|
Mes specific conventions
Java enums
For every enum field of a model we create, we should create corresponding Java enum in constants package.
For ex.
Code Block | ||
---|---|---|
| ||
public enum BatchNumberUniqueness { GLOBALLY("01globally"), MANUFACTURER("02manufacturer"); private String stringValue; private BatchNumberUniqueness(final String stringValue) { this.stringValue = stringValue; } public String getStringValue() { return stringValue; } public static final BatchNumberUniqueness parseString(final String string) { if ("01globally".equals(string)) { return GLOBALLY; } else if ("02manufacturer".equals(string)) { return MANUFACTURER; } else { throw new IllegalStateException("Couldn't parse BatchNumberUniqueness from string"); } } } |