Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create a class named <strong>SalaryReport</strong> which is composed of many objects of <strong>SalaryReportRow</strong>.</p> <p>In a <strong>SalaryReport</strong> you have a method name <em>calculate</em>() which executes all the algorithms. <strong>SalaryReportRow</strong> can be specialized in many type of rows that suit your needs.</p> <pre><code>class SalaryReport { private List&lt;SalaryReportRow&gt; rows; private List&lt;SalaryCalculator&gt; calculators; private HashMap&lt;SalaryCalculator,List&lt;SalaryReportRow&gt;&gt; results; ... public float getResults() { } public void applyCalculators(){ for(SalaryCalculator s : calculators){ results.put(s,s.execute(rows)); } } public void setSalaryCalculators(List&lt;SalaryCalculator&gt; calculators){ this.calculators = calculators; } public float getCalculation(SalaryCalculator s){ return results.get(s); } ... } </code></pre> <p>When calculating taxes you can use a <a href="http://en.wikipedia.org/wiki/Strategy_pattern" rel="nofollow">Strategy Pattern</a> to mantain your code more flexible. If you have to combine many strategies you can use also a <a href="http://en.wikipedia.org/wiki/Composite_pattern" rel="nofollow">Composite Pattern</a> with Strategy or a <a href="http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern" rel="nofollow">Chain of Responsibility</a> with Strategy.</p> <pre><code>abstract class SalaryCalculator implements Calculator { //Order of children matters protected List&lt;SalaryCalculator&gt; children = new ArrayList&lt;SalaryCalculator&gt;; public List&lt;SalaryReportRow&gt; execute(List&lt;SalaryReportRow&gt; rows){ List&lt;SalaryReportRow&gt; result_rows = new ArrayList&lt;SalaryReportRow&gt; (rows); for(SalaryCalculator s: children){ result_rows = s.execute(result_rows); } return result_rows; } } class TaxCalculator extends SalaryCalculator { public List&lt;SalaryReportRow&gt; execute(List&lt;SalaryReportRow&gt; rows){ List&lt;SalaryReportRow&gt; result_rows = super.execute(rows); // } } class MaxSalaryCalculator extends SalaryCalculator { public List&lt;SalaryReportRow&gt; execute(List&lt;SalaryReportRow&gt; rows){ List&lt;SalaryReportRow&gt; result_rows = super.execute(rows); ... } } class MaxSalaryWithTaxCalculator extends SalaryCalculator { public MaxSalaryWithTaxCalculator() { children.add(new MaxSalaryCalculator()); children.add(new TaxCalculator()); } public List&lt;SalaryReportRow&gt; execute(List&lt;SalaryReportRow&gt; rows){ List&lt;SalaryReportRow&gt; result_rows = super.execute(rows); ... } } </code></pre> <p>So the <strong>SalaryReport</strong> will have a method called <em>setSalaryCalculators(List)</em> (you can use also more than one algorithms at once), where List is a list that contains all the strategies applied.</p> <p>You will have more <strong>SalaryReportRows</strong>:</p> <ol> <li>One for taxes.</li> <li>One for money earned.</li> <li>...</li> </ol> <p>So you can easily calculate all steps.</p> <p>When you communicate with storage handlers I suggest to use a <a href="http://www.oracle.com/technetwork/java/dataaccessobject-138824.html" rel="nofollow">DAO pattern</a> with interfaces which is responsible of creating and saving objects.</p> <p>I hope this will be helpful. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload