mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 20:58:35 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -30,13 +30,13 @@ import com.iluwatar.separatedinterface.taxes.ForeignTaxCalculator;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>The Separated Interface pattern encourages to separate the interface definition and
|
||||
* The Separated Interface pattern encourages to separate the interface definition and
|
||||
* implementation in different packages. This allows the client to be completely unaware of the
|
||||
* implementation.</p>
|
||||
* implementation.
|
||||
*
|
||||
* <p>In this class the {@link InvoiceGenerator} class is injected with different instances of
|
||||
* {@link com.iluwatar.separatedinterface.invoice.TaxCalculator} implementations located in separate
|
||||
* packages, to receive different responses for both of the implementations.</p>
|
||||
* packages, to receive different responses for both of the implementations.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
@@ -49,12 +49,12 @@ public class App {
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
//Create the invoice generator with product cost as 50 and foreign product tax
|
||||
var internationalProductInvoice = new InvoiceGenerator(PRODUCT_COST,
|
||||
new ForeignTaxCalculator());
|
||||
// Create the invoice generator with product cost as 50 and foreign product tax
|
||||
var internationalProductInvoice =
|
||||
new InvoiceGenerator(PRODUCT_COST, new ForeignTaxCalculator());
|
||||
LOGGER.info("Foreign Tax applied: {}", "" + internationalProductInvoice.getAmountWithTax());
|
||||
|
||||
//Create the invoice generator with product cost as 50 and domestic product tax
|
||||
// Create the invoice generator with product cost as 50 and domestic product tax
|
||||
var domesticProductInvoice = new InvoiceGenerator(PRODUCT_COST, new DomesticTaxCalculator());
|
||||
LOGGER.info("Domestic Tax applied: {}", "" + domesticProductInvoice.getAmountWithTax());
|
||||
}
|
||||
|
||||
+3
-5
@@ -27,13 +27,11 @@ 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 record InvoiceGenerator(double amount, TaxCalculator taxCalculator) {
|
||||
/** TaxCalculator description:
|
||||
* The TaxCalculator interface to calculate the payable tax.
|
||||
* Amount description:
|
||||
* The base product amount without tax.
|
||||
/**
|
||||
* TaxCalculator description: The TaxCalculator interface to calculate the payable tax. Amount
|
||||
* description: The base product amount without tax.
|
||||
*/
|
||||
public double getAmountWithTax() {
|
||||
return amount + taxCalculator.calculate(amount);
|
||||
|
||||
+1
-4
@@ -24,11 +24,8 @@
|
||||
*/
|
||||
package com.iluwatar.separatedinterface.invoice;
|
||||
|
||||
/**
|
||||
* TaxCalculator interface to demonstrate The Separated Interface pattern.
|
||||
*/
|
||||
/** TaxCalculator interface to demonstrate The Separated Interface pattern. */
|
||||
public interface TaxCalculator {
|
||||
|
||||
double calculate(double amount);
|
||||
|
||||
}
|
||||
|
||||
+1
-4
@@ -26,9 +26,7 @@ package com.iluwatar.separatedinterface.taxes;
|
||||
|
||||
import com.iluwatar.separatedinterface.invoice.TaxCalculator;
|
||||
|
||||
/**
|
||||
* TaxCalculator for Domestic goods with 20% tax.
|
||||
*/
|
||||
/** TaxCalculator for Domestic goods with 20% tax. */
|
||||
public class DomesticTaxCalculator implements TaxCalculator {
|
||||
|
||||
public static final double TAX_PERCENTAGE = 20;
|
||||
@@ -37,5 +35,4 @@ public class DomesticTaxCalculator implements TaxCalculator {
|
||||
public double calculate(double amount) {
|
||||
return amount * TAX_PERCENTAGE / 100.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-4
@@ -26,9 +26,7 @@ package com.iluwatar.separatedinterface.taxes;
|
||||
|
||||
import com.iluwatar.separatedinterface.invoice.TaxCalculator;
|
||||
|
||||
/**
|
||||
* TaxCalculator for foreign goods with 60% tax.
|
||||
*/
|
||||
/** TaxCalculator for foreign goods with 60% tax. */
|
||||
public class ForeignTaxCalculator implements TaxCalculator {
|
||||
|
||||
public static final double TAX_PERCENTAGE = 60;
|
||||
@@ -37,5 +35,4 @@ public class ForeignTaxCalculator implements TaxCalculator {
|
||||
public double calculate(double amount) {
|
||||
return amount * TAX_PERCENTAGE / 100.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user