In the following code of A* algorithm here, I have 2 functions setG
and calcF
, such that -
setG
must be called before calcF
&&calcF
must be called after setG
in other words, simply calling setG
without calling calcF
later is incorrect. Also, simply calling calcF
without calling setG
before is incorrect. Calling calcF
before setG
is incorrect.
How can this rule be enfored to the client ?
A similar question exists here, but there is a minute difference. This question is more stricter in conditions.
The first idea would be to merge those functions into one function setGAndCalcF()
:
private void setG(int g);
private void calcF(T destination);
public void setGAndCalcF(int g, T destination) {
setG(g);
calcF(destination);
}
If this is not feasible you can implement runtime checks (plus documentation) into setG()
and calcF()
which would throw an Exception (e.g. IllegalStateException
).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments