The BugBounty project contains a tricky problem.
On the one hand you want to store a number of found bugs, they contain the reason and the company for which that bug applies. Inversely it would be useful to keep a list of bugs in each company to calculate its total bounty.
This is a Bad Design, ideally the relations between all classes in your project should form a tree, a circular implementation may cause trouble, but a loop in which two classes directly depend on each other is not good.
Confirm that the BountyAdministrator
is implemented correctly.
Implement a unittest.
To solve the main problem by making an interface for retrieving the total bounty:
public interface TotalBountyCalculator {
int getTotalBounty();
}
This takes the responsibility to store a BugList from the Client to a separate “CalculateTheTotal” class. It doesn’t solve the circular reference, but this way, the Client class only sees an implementation to find the total bounty. Only the BountyCalculator knows how to do that with an ArrayList of BugBounties.
Depending on the way to you implement this, a streams solution might be useful.
Direct loops are very bad. You can break that direct connection by supplying an interface that solves the problem. But without giving direct access to the data source(s).