Immutable classes contribute to the distribution of objects, but if you want security, mutable objects will increase the distribution of objects because you need to return copies, not the original, so that the user cannot modify the returned object.
Regarding the use of classes with all static methods, this is not really an option in most cases where immutability can be used. Take this example from an RPG:
public class Weapon { final private int attackBonus; final private int accuracyBonus; final private int range; public Weapon(int attackBonus, int accuracyBonus, int range) { this.attackBonus = attackBonus; this.accuracyBonus = accuracyBonus; this.range = range; } public int getAttackBonus() { return this.attackBonus; } public int getAccuracyBonus() { return this.accuracyBonus; } public int getRange() { return this.range; } }
How exactly do you implement this with a class that contains only static methods?
Imagist Aug 16 '09 at 19:43 2009-08-16 19:43
source share