#Tightly coupling classes

1 messages · Page 1 of 1 (latest)

naive plinth
#

I have 2 classes, a 'unit' class, and a 'skill' class.

    protected ArrayList<Skill> skills;
    protected double skillHaste;
}```

```public class Skill {
    protected final double baseCooldown;
    protected double cooldown;

    protected double getCooldown() {
      return this.baseCooldown / (1 + skillHaste); //Error as skillHaste is unknown
    } 
}```

My problem is the 'Skill' class does not have access to the 'Unit' class. How can I resolve this problem where I need the skill haste information from the 'Unit' class in the 'Skill' class?

I thought about using 'Unit' class a field in the 'Skill' class, but I've read that it's anti-pattern. Is there a better solution?
raven parcelBOT
#

<@&987246399047479336> please have a look, thanks.

raven parcelBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

devout flower
#

aaand?

naive plinth
# sick dove what is skillhaste ?

skill haste is how much faster your skill comes back up. For example, if a skill cooldown is 60 seconds and you have 100% skill haste, the cooldown is now 30 seconds.

#

skillhaste is part of a unit attribute.

sick dove
#

you could pass skillHaste to getCooldown

#

or directly create skills from units while passing skillHaste

naive plinth
naive plinth
devout flower
#

as method parameter for example

naive plinth
#

Oh lol. I think doing this


}```
Kinda works. Don't know why I didn't think of this earlier.