Skip to main content
Included full code of the composition class
Source Link
public class Composition  {

    private ArrayList<Tank> tanks;
    private ArrayList<DamageDealer> damageDealers;
    private ArrayList<Healer> healers;
    private ArrayList<Bruiser> bruisers;
    
    private boolean doubleSupport;
    private boolean doubleWarrior;
    private boolean heavyDamage;
    private boolean lockdownProtection;

    private int mobility;
    private int waveclear;
    private int nuMelee;
    private int nuRange;
    private int lockdown;

    private int burstMitigation;
    private int sustainedMitigation;

    private int damage;
    private int burstDamageRating;
    private int sustainedDamageRating;

    private int frontlineRating;
    private int defensiveRating;
    private int offensiveRating;

    public Composition() {
        this.tanks = new  ArrayList<Tank>();
        this.damageDealers = new ArrayList<DamageDealer>();
        this.healers = new ArrayList<Healer>();
        this.bruisers = new ArrayList<Bruiser>();
    }

    private void addMutualContribution(Role r) {
        this.mobility += r.getMobility();
        this.defensiveRating += r.getPeeling();
        this.waveclear += r.getWaveclear();
        this.burstMitigation += r.getBurstMitigaion();
        this.sustainedMitigation += r.getSustainedMitigation();
    }

    public void addBruiserContribution(Bruiser b) {
        addMutualContribution(b);
        this.offensiveRating += b.getPressure();
        this.damage += b.getDamage();
        this.frontlineRating += b.getFrontlineRating();
        
        addBruiser(b);
    }

    public void addDDContribution(DamageDealer d) {
        addMutualContribution(d);
        this.burstDamageRating += d.getBurstDamageRating();
        this.sustainedDamageRating += d.getSustainedDamageRating();
        this.damage += d.getDamageOutput();
        this.offensiveRating += d.getAggression(); 

        addDamageDealer(d);
    }

    public void addTankContribution(Tank t) {
        addMutualContribution(t);
        this.defensiveRating += t.getAntiMeleeEffectiveness();
        this.offensiveRating += t.getEngage();
        this.frontlineRating += t.getFrontlineRating();
        
        addTank(t);
    }

    public void addHealerContribution(Healer h) {
        addMutualContribution(h);
        this.burstMitigation += h.getBurstHealing();
        this.sustainedMitigation += h.getSustainedHealing();

        if (h.hasLockdownProtection()) {
            this.lockdownProtection = true;
        }
        
        addHealer(h);

    }

    private void addTank(Tank t) {
        tanks.add(t);

        if (tanks.size() + bruisers.size() > 1) {
            setDoubleWarrior(true);
        }

    }

    private void addHealer(Healer h) {
        healers.add(h);

        if (healers.size() == 2) {
            setDoubleSupport(true);
        }

    }

    private void addDamageDealer(DamageDealer d) {
        damageDealers.add(d);

        if (damageDealers.size() + bruisers.size() > 2) {
            setHeavyDamage(true);
        }
    }

    private void addBruiser(Bruiser b) {
        bruisers.add(b);

        if(bruisers.size() + damageDealers.size() > 2) {
            setHeavyDamage(true);
        }
    }

    private void setDoubleWarrior(boolean b) {
        doubleWarrior = b;
    }

    private void setDoubleSupport(boolean b) {
        doubleSupport = b;
    }

    private void setHeavyDamage(boolean b) {
        heavyDamage = b;
    }
}
public class Composition  {

    private ArrayList<Tank> tanks;
    private ArrayList<DamageDealer> damageDealers;
    private ArrayList<Healer> healers;
    private ArrayList<Bruiser> bruisers;

    private boolean lockdownProtection;

    private int mobility;
    private int waveclear;
    private int nuMelee;
    private int nuRange;
    private int lockdown;

    private int burstMitigation;
    private int sustainedMitigation;

    private int damage;
    private int burstDamageRating;
    private int sustainedDamageRating;

    private int frontlineRating;
    private int defensiveRating;
    private int offensiveRating;

    public Composition() {
        this.tanks = new  ArrayList<Tank>();
        this.damageDealers = new ArrayList<DamageDealer>();
        this.healers = new ArrayList<Healer>();
        this.bruisers = new ArrayList<Bruiser>();
    }

    private void addMutualContribution(Role r) {
        this.mobility += r.getMobility();
        this.defensiveRating += r.getPeeling();
        this.waveclear += r.getWaveclear();
        this.burstMitigation += r.getBurstMitigaion();
        this.sustainedMitigation += r.getSustainedMitigation();
    }

    public void addBruiserContribution(Bruiser b) {
        addMutualContribution(b);
        this.offensiveRating += b.getPressure();
        this.damage += b.getDamage();
        this.frontlineRating += b.getFrontlineRating();
    }

    public void addDDContribution(DamageDealer d) {
        addMutualContribution(d);
        this.burstDamageRating += d.getBurstDamageRating();
        this.sustainedDamageRating += d.getSustainedDamageRating();
        this.damage += d.getDamageOutput();
        this.offensiveRating += d.getAggression();
    }

    public void addTankContribution(Tank t) {
        addMutualContribution(t);
        this.defensiveRating += t.getAntiMeleeEffectiveness();
        this.offensiveRating += t.getEngage();
        this.frontlineRating += t.getFrontlineRating();
    }

    public void addHealerContribution(Healer h) {
        addMutualContribution(h);
        this.burstMitigation += h.getBurstHealing();
        this.sustainedMitigation += h.getSustainedHealing();

        if (h.hasLockdownProtection()) {
            this.lockdownProtection = true;
        }

    }
}
public class Composition  {

    private ArrayList<Tank> tanks;
    private ArrayList<DamageDealer> damageDealers;
    private ArrayList<Healer> healers;
    private ArrayList<Bruiser> bruisers;
    
    private boolean doubleSupport;
    private boolean doubleWarrior;
    private boolean heavyDamage;
    private boolean lockdownProtection;

    private int mobility;
    private int waveclear;
    private int nuMelee;
    private int nuRange;
    private int lockdown;

    private int burstMitigation;
    private int sustainedMitigation;

    private int damage;
    private int burstDamageRating;
    private int sustainedDamageRating;

    private int frontlineRating;
    private int defensiveRating;
    private int offensiveRating;

    public Composition() {
        this.tanks = new  ArrayList<Tank>();
        this.damageDealers = new ArrayList<DamageDealer>();
        this.healers = new ArrayList<Healer>();
        this.bruisers = new ArrayList<Bruiser>();
    }

    private void addMutualContribution(Role r) {
        this.mobility += r.getMobility();
        this.defensiveRating += r.getPeeling();
        this.waveclear += r.getWaveclear();
        this.burstMitigation += r.getBurstMitigaion();
        this.sustainedMitigation += r.getSustainedMitigation();
    }

    public void addBruiserContribution(Bruiser b) {
        addMutualContribution(b);
        this.offensiveRating += b.getPressure();
        this.damage += b.getDamage();
        this.frontlineRating += b.getFrontlineRating();
        
        addBruiser(b);
    }

    public void addDDContribution(DamageDealer d) {
        addMutualContribution(d);
        this.burstDamageRating += d.getBurstDamageRating();
        this.sustainedDamageRating += d.getSustainedDamageRating();
        this.damage += d.getDamageOutput();
        this.offensiveRating += d.getAggression(); 

        addDamageDealer(d);
    }

    public void addTankContribution(Tank t) {
        addMutualContribution(t);
        this.defensiveRating += t.getAntiMeleeEffectiveness();
        this.offensiveRating += t.getEngage();
        this.frontlineRating += t.getFrontlineRating();
        
        addTank(t);
    }

    public void addHealerContribution(Healer h) {
        addMutualContribution(h);
        this.burstMitigation += h.getBurstHealing();
        this.sustainedMitigation += h.getSustainedHealing();

        if (h.hasLockdownProtection()) {
            this.lockdownProtection = true;
        }
        
        addHealer(h);

    }

    private void addTank(Tank t) {
        tanks.add(t);

        if (tanks.size() + bruisers.size() > 1) {
            setDoubleWarrior(true);
        }

    }

    private void addHealer(Healer h) {
        healers.add(h);

        if (healers.size() == 2) {
            setDoubleSupport(true);
        }

    }

    private void addDamageDealer(DamageDealer d) {
        damageDealers.add(d);

        if (damageDealers.size() + bruisers.size() > 2) {
            setHeavyDamage(true);
        }
    }

    private void addBruiser(Bruiser b) {
        bruisers.add(b);

        if(bruisers.size() + damageDealers.size() > 2) {
            setHeavyDamage(true);
        }
    }

    private void setDoubleWarrior(boolean b) {
        doubleWarrior = b;
    }

    private void setDoubleSupport(boolean b) {
        doubleSupport = b;
    }

    private void setHeavyDamage(boolean b) {
        heavyDamage = b;
    }
}
Included full code of the composition class
Source Link

I have a Composition object that contains 4 ArrayList objects, each of which contains objects of a particular subclass of my Abstract class Role. The 4 subclasses are Bruiser, Healer, Tank, and DamageDealer. The point of the program is to analyze two opposing Composition objects as they are being built (players fill their Composition object one Role pick at a time), and based on each of their properties, recommend to the player a particular Hero for a particular Role that would suit the player's Composition.

The values of the Composition object's properties are incremented accordingly each time a Role subclass gets added to one of its ArrayLists, like so (note: "this" corresponds to the Composition object):

public class Composition  {

    private ArrayList<Tank> tanks;
    private ArrayList<DamageDealer> damageDealers;
    private ArrayList<Healer> healers;
    private ArrayList<Bruiser> bruisers;

    private boolean lockdownProtection;

    private int mobility;
    private int waveclear;
    private int nuMelee;
    private int nuRange;
    private int lockdown;

    private int burstMitigation;
    private int sustainedMitigation;

    private int damage;
    private int burstDamageRating;
    private int sustainedDamageRating;

    private int frontlineRating;
    private int defensiveRating;
    private int offensiveRating;

    public Composition() {
        this.tanks = new  ArrayList<Tank>();
        this.damageDealers = new ArrayList<DamageDealer>();
        this.healers = new ArrayList<Healer>();
        this.bruisers = new ArrayList<Bruiser>();
    }

    private void addMutualContribution(Role r) {
        this.mobility += r.getMobility();
        this.defensiveRating += r.getPeeling();
        this.waveclear += r.getWaveclear();
        this.burstMitigation += r.getBurstMitigaion();
        this.sustainedMitigation += r.getSustainedMitigation();
    }

    public void addBruiserContribution(Bruiser b) {
        addMutualContribution(b);
        this.offensiveRating += b.getPressure();
        this.damage += b.getDamage();
        this.frontlineRating += b.getFrontlineRating();
    }

    public void addDDContribution(DamageDealer d) {
        addMutualContribution(d);
        this.burstDamageRating += d.getBurstDamageRating();
        this.sustainedDamageRating += d.getSustainedDamageRating();
        this.damage += d.getDamageOutput();
        this.offensiveRating += d.getAggression();
    }

    public void addTankContribution(Tank t) {
        addMutualContribution(t);
        this.defensiveRating += t.getAntiMeleeEffectiveness();
        this.offensiveRating += t.getEngage();
        this.frontlineRating += t.getFrontlineRating();
    }

    public void addHealerContribution(Healer h) {
        addMutualContribution(h);
        this.burstMitigation += h.getBurstHealing();
        this.sustainedMitigation += h.getSustainedHealing();

        if (h.hasLockdownProtection()) {
            this.lockdownProtection = true;
        } 

    }
}

Composition Class (minus property "getters"):

I have a Composition object that contains 4 ArrayList objects, each of which contains objects of a particular subclass of my Abstract class Role. The 4 subclasses are Bruiser, Healer, Tank, and DamageDealer. The values of the Composition object's properties are incremented accordingly each time a Role subclass gets added to one of its ArrayLists, like so (note: "this" corresponds to the Composition object):

private void addMutualContribution(Role r) {
    this.mobility += r.getMobility();
    this.defensiveRating += r.getPeeling();
    this.waveclear += r.getWaveclear();
    this.burstMitigation += r.getBurstMitigaion();
    this.sustainedMitigation += r.getSustainedMitigation();
}

public void addBruiserContribution(Bruiser b) {
    addMutualContribution(b);
    this.offensiveRating += b.getPressure();
    this.damage += b.getDamage();
    this.frontlineRating += b.getFrontlineRating();
}

public void addDDContribution(DamageDealer d) {
    addMutualContribution(d);
    this.burstDamageRating += d.getBurstDamageRating();
    this.sustainedDamageRating += d.getSustainedDamageRating();
    this.damage += d.getDamageOutput();
    this.offensiveRating += d.getAggression();
}

public void addTankContribution(Tank t) {
    addMutualContribution(t);
    this.defensiveRating += t.getAntiMeleeEffectiveness();
    this.offensiveRating += t.getEngage();
    this.frontlineRating += t.getFrontlineRating();
}

public void addHealerContribution(Healer h) {
    addMutualContribution(h);
    this.burstMitigation += h.getBurstHealing();
    this.sustainedMitigation += h.getSustainedHealing();

    if (h.hasLockdownProtection()) {
        this.lockdownProtection = true;
    }

}

I have a Composition object that contains 4 ArrayList objects, each of which contains objects of a particular subclass of my Abstract class Role. The 4 subclasses are Bruiser, Healer, Tank, and DamageDealer. The point of the program is to analyze two opposing Composition objects as they are being built (players fill their Composition object one Role pick at a time), and based on each of their properties, recommend to the player a particular Hero for a particular Role that would suit the player's Composition.

The values of the Composition object's properties are incremented accordingly each time a Role subclass gets added to one of its ArrayLists, like so (note: "this" corresponds to the Composition object):

public class Composition  {

    private ArrayList<Tank> tanks;
    private ArrayList<DamageDealer> damageDealers;
    private ArrayList<Healer> healers;
    private ArrayList<Bruiser> bruisers;

    private boolean lockdownProtection;

    private int mobility;
    private int waveclear;
    private int nuMelee;
    private int nuRange;
    private int lockdown;

    private int burstMitigation;
    private int sustainedMitigation;

    private int damage;
    private int burstDamageRating;
    private int sustainedDamageRating;

    private int frontlineRating;
    private int defensiveRating;
    private int offensiveRating;

    public Composition() {
        this.tanks = new  ArrayList<Tank>();
        this.damageDealers = new ArrayList<DamageDealer>();
        this.healers = new ArrayList<Healer>();
        this.bruisers = new ArrayList<Bruiser>();
    }

    private void addMutualContribution(Role r) {
        this.mobility += r.getMobility();
        this.defensiveRating += r.getPeeling();
        this.waveclear += r.getWaveclear();
        this.burstMitigation += r.getBurstMitigaion();
        this.sustainedMitigation += r.getSustainedMitigation();
    }

    public void addBruiserContribution(Bruiser b) {
        addMutualContribution(b);
        this.offensiveRating += b.getPressure();
        this.damage += b.getDamage();
        this.frontlineRating += b.getFrontlineRating();
    }

    public void addDDContribution(DamageDealer d) {
        addMutualContribution(d);
        this.burstDamageRating += d.getBurstDamageRating();
        this.sustainedDamageRating += d.getSustainedDamageRating();
        this.damage += d.getDamageOutput();
        this.offensiveRating += d.getAggression();
    }

    public void addTankContribution(Tank t) {
        addMutualContribution(t);
        this.defensiveRating += t.getAntiMeleeEffectiveness();
        this.offensiveRating += t.getEngage();
        this.frontlineRating += t.getFrontlineRating();
    }

    public void addHealerContribution(Healer h) {
        addMutualContribution(h);
        this.burstMitigation += h.getBurstHealing();
        this.sustainedMitigation += h.getSustainedHealing();

        if (h.hasLockdownProtection()) {
            this.lockdownProtection = true;
        } 

    }
}

Composition Class (minus property "getters"):

Post Reopened by forsvarir, ChrisWue, t3chb0t, mdfst13, alecxe
deleted 46 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

I have a CompositionComposition object that contains 4 ArrayListArrayList objects, each of which contains objects of a particular subclass of my AbstractAbstract class "Role"Role. The 4 subclasses are BruiserBruiser, HealerHealer, TankTank, Damage Dealerand DamageDealer. The values of the CompositionComposition object's properties are incremented accordingly each time a RoleRole subclass gets added to one of its ArrayListsArrayLists, like so (note: "this" corresponds to the CompositionComposition object)  :

To me, this implementation feels backwards. Ultimately I should only have the one public method to add a RoleRole subclass to the composition, then the CompositionComposition should privately adjust its own properties based on which particular subclass is being added, something like this:

This doesn't work without me having to hardcast the RoleRole abstract class into a particular subclass before passing it to the appropriate "add__Contribution()"add__Contribution() method, which is a big red-flag. Thus it feels like I missed an opportunity for cleaner polymorphism, but I can't figure out where.

Edit: Including more of my code to further flesh out my problem!

I have a Composition object that contains 4 ArrayList objects, each of which contains objects of a particular subclass of my Abstract class "Role". The 4 subclasses are Bruiser, Healer, Tank, Damage Dealer. The values of the Composition object's properties are incremented accordingly each time a Role subclass gets added to one of its ArrayLists, like so (note: "this" corresponds to the Composition object)  :

To me, this implementation feels backwards. Ultimately I should only have the one public method to add a Role subclass to the composition, then the Composition should privately adjust its own properties based on which particular subclass is being added, something like this:

This doesn't work without me having to hardcast the Role abstract class into a particular subclass before passing it to the appropriate "add__Contribution()" method, which is a big red-flag. Thus it feels like I missed an opportunity for cleaner polymorphism, but I can't figure out where.

Edit: Including more of my code to further flesh out my problem!

I have a Composition object that contains 4 ArrayList objects, each of which contains objects of a particular subclass of my Abstract class Role. The 4 subclasses are Bruiser, Healer, Tank, and DamageDealer. The values of the Composition object's properties are incremented accordingly each time a Role subclass gets added to one of its ArrayLists, like so (note: "this" corresponds to the Composition object):

To me, this implementation feels backwards. Ultimately I should only have the one public method to add a Role subclass to the composition, then the Composition should privately adjust its own properties based on which particular subclass is being added, something like this:

This doesn't work without me having to hardcast the Role abstract class into a particular subclass before passing it to the appropriate add__Contribution() method, which is a big red-flag. Thus it feels like I missed an opportunity for cleaner polymorphism, but I can't figure out where.

Fleshed out code to include everything relevant to the abstract and subclasses in question
Source Link
Loading
Post Closed as "Not suitable for this site" by mdfst13, alecxe, t3chb0t, ChrisWue, Abbas
Source Link
Loading