lundi 23 mars 2015

Immutable vs Read-only vs Unmodifiable naming difference


So, I've looked at some similar questions asked here in regards to how these three should be used in naming. Usually, the answer is something along the lines of "it's conventional" and "just be consistent". I'm wondering if that's the same answer for my question.


I have an interface StatSet defined as



public interface StatSet {

int getHitpoints();

int getAttack();

int getDefense();
}


I want to define an implementation, where all fields are defined in the constructor:



public final class ReadOnlyStatSet {

public ReadOnlyStatSet(final int hitpoints, final int attack, final int defense) {
this.hitpoints = hitpoints;
this.attack = attack;
this.defense = defense;
}

public int getHitpoints() {
return hitpoints;
}

public int getAttack() {
return attack;
}

public int getDefense() {
return defense;
}

private final int hitpoints;
private final int attack;
private final int defense;
// no other fields
}


My question is: is ReadOnlyStatSet the best name for this type of class. Or, would Immutable be more suited. In which grammar would I use one over the other.





Aucun commentaire:

Enregistrer un commentaire