Skip to main content
added 518 characters in body
Source Link
E-K
  • 436
  • 3
  • 5

Enum are a good way to do this in my opinion if this is really static.

Might I suggest you do:

public enum Datafile {
    ACTIVITIES("activities.yaml"),
    OPEN_LOOPS("open_loops.yaml");

private String filepath;

private Datafile(String filepath) {
    this.filepath = filepath;
}
        
public String getFilepath() {
    return filepath;
}

This is a bit more readable than the overriden methods in each declaration, especially with long enums.

If the values of the filepaths are subject to changes from time to time. I suggest using a properties file. These can be reloaded without recompiling you package, meaning non-developers could maintain them. That is useful in some team setups.

EDIT: For properties, I suggest you read the java properties tutorial: http://download.oracle.com/javase/tutorial/essential/environment/properties.html. There are also a lot of already well written tutorials about them and I could never hope to match their quality here. Also, never having worked on Android, I do not know if google has provided something that is more user friendly.

For small applications, I would go for enums personally, as they are very easy to manage and usually do the job pretty well.

Enum are a good way to do this in my opinion if this is really static.

Might I suggest you do:

public enum Datafile {
    ACTIVITIES("activities.yaml"),
    OPEN_LOOPS("open_loops.yaml");

private String filepath;

private Datafile(String filepath) {
    this.filepath = filepath;
}
        
public String getFilepath() {
    return filepath;
}

This is a bit more readable than the overriden methods in each declaration, especially with long enums.

If the values of the filepaths are subject to changes from time to time. I suggest using a properties file. These can be reloaded without recompiling you package, meaning non-developers could maintain them. That is useful in some team setups.

Enum are a good way to do this in my opinion if this is really static.

Might I suggest you do:

public enum Datafile {
    ACTIVITIES("activities.yaml"),
    OPEN_LOOPS("open_loops.yaml");

private String filepath;

private Datafile(String filepath) {
    this.filepath = filepath;
}
        
public String getFilepath() {
    return filepath;
}

This is a bit more readable than the overriden methods in each declaration, especially with long enums.

If the values of the filepaths are subject to changes from time to time. I suggest using a properties file. These can be reloaded without recompiling you package, meaning non-developers could maintain them. That is useful in some team setups.

EDIT: For properties, I suggest you read the java properties tutorial: http://download.oracle.com/javase/tutorial/essential/environment/properties.html. There are also a lot of already well written tutorials about them and I could never hope to match their quality here. Also, never having worked on Android, I do not know if google has provided something that is more user friendly.

For small applications, I would go for enums personally, as they are very easy to manage and usually do the job pretty well.

Source Link
E-K
  • 436
  • 3
  • 5

Enum are a good way to do this in my opinion if this is really static.

Might I suggest you do:

public enum Datafile {
    ACTIVITIES("activities.yaml"),
    OPEN_LOOPS("open_loops.yaml");

private String filepath;

private Datafile(String filepath) {
    this.filepath = filepath;
}
        
public String getFilepath() {
    return filepath;
}

This is a bit more readable than the overriden methods in each declaration, especially with long enums.

If the values of the filepaths are subject to changes from time to time. I suggest using a properties file. These can be reloaded without recompiling you package, meaning non-developers could maintain them. That is useful in some team setups.