Using public finite member variables and redefined methods in the constructor

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:

/** A monster that fights other monsters in my program */
public abstract class Creature
{

    /**
     * Keeps track of the different values determining how powerful a Creature
     * is.
     */
    public static class Stats
    {
        //subclass definition here.
        //This subclass contains a lot of public static members like this:
        public final CurMax health;
    }

    public final static Random RANDOM = new Random();

    //These are the public final members that I'm wondering about.
    public final Stats stats;
    public final Attack[] attacks;
    public final Stopwatch turnStopwatch;
    private String name;

    //This is the constructor I'm wondering about.
    public Creature()
    {
    initMembers();
    stats = generateStats();
    name = RandomValues.NAMES[RANDOM.nextInt(RandomValues.NAMES.length)];
    attacks = generateAttacks();
    turnStopwatch = new Stopwatch(false);
    }

    /**
     * Define any member variables for subclasses in Creature in this method,
     * not in the subclasses' constructors.
     *
     * Using the Creature class requires the Constructor to call overridable
     * methods. This is deliberate because the constructor assigns values to
     * final member variables, but I want the values of these variables to be
     * determined by subclasses. This method allows subclasses to assign values
     * to their own member variables while still controlling the values of the
     * final variables in the Creature class.
     *
     * @see #generateAttacks()
     * @see #generateStats()
     */
    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() .

? , ?

+5
2

getters Stats, Health .., ? , :

creature.getStats().getHealth().getCurrent();

IDE, , , , , . . , , , .

: , - Abstract Factory . , , . () Factory :

public interface CreatureFactory {
    public Stats newStats();
    public Attack newAttack();
}

public class Creature {
    public Creature(CreatureFactory f) {
      this.stats = f.newStats();
      this.attack = f.newAttack();
    }
}

public class Monster extends Creature {
    public Monster() {
        super(new MonsterFactory());
    }
}

Factory .

+7

generateStats() generateAttack()?

0

All Articles