mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 04:59:24 +00:00
* Issue #2377: The repository code has been refactored to use the record class * Issue #2377: Refactored according to the rules defined for the repo code * Issue #2377: Refactored according to the rules defined for the repo code * Issue #2377: Refactored according to the rules defined for the repo code
This commit is contained in:
+5
-16
@@ -27,26 +27,15 @@ package com.iluwatar.separatedinterface.invoice;
|
||||
/**
|
||||
* InvoiceGenerator class generates an invoice, accepting the product cost and calculating the total
|
||||
* price payable inclusive tax (calculated by {@link TaxCalculator}).
|
||||
*
|
||||
*/
|
||||
public class InvoiceGenerator {
|
||||
|
||||
/**
|
||||
public record InvoiceGenerator(double amount, TaxCalculator taxCalculator) {
|
||||
/** TaxCalculator description:
|
||||
* The TaxCalculator interface to calculate the payable tax.
|
||||
*/
|
||||
private final TaxCalculator taxCalculator;
|
||||
|
||||
/**
|
||||
* Amount description:
|
||||
* The base product amount without tax.
|
||||
*/
|
||||
private final double amount;
|
||||
|
||||
public InvoiceGenerator(double amount, TaxCalculator taxCalculator) {
|
||||
this.amount = amount;
|
||||
this.taxCalculator = taxCalculator;
|
||||
}
|
||||
|
||||
public double getAmountWithTax() {
|
||||
return amount + taxCalculator.calculate(amount);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user