I have questions about the pair methods that I use when developing a class. I declared some of its members a public finale instead of a private one, and the constructor calls the redefined methods. I know this is usually considered bad practice, but I think they can be justified in my situation, and I want to know what others think.
This is my class:
public abstract class Creature
{
public static class Stats
{
public final CurMax health;
}
public final static Random RANDOM = new Random();
public final Stats stats;
public final Attack[] attacks;
public final Stopwatch turnStopwatch;
private String name;
public Creature()
{
initMembers();
stats = generateStats();
name = RandomValues.NAMES[RANDOM.nextInt(RandomValues.NAMES.length)];
attacks = generateAttacks();
turnStopwatch = new Stopwatch(false);
}
protected abstract void initMembers();
protected abstract Stats generateStats();
protected abstract Attack[] generateAttacks();
public boolean isDead()
{
return stats.health.getCurrent() <= 0;
}
public String getName()
{
return name;
}
}
- , , . , :
creature.stats.health.getCurrent();
creature.stats.health.resetMax();
, , getCurrentHealth() resetMaxHealth(), , . CurMax 10 , , 12 , CurMax, 100 . , ? , ?
, ? , . , , , . stats attacks , . , , stats attacks, .
, , , , override , . , , generateStats() generateAttacks() . , , initMembers, - . - generateStats() generateAttacks().
Stats Attack , Stats Attacks . super() .
? , ?