Hexagonal Architecture in Java

This commit is contained in:
DESKTOP-MG5QNKB\harsha 2019-06-09 00:19:20 -04:00
parent 8d6e70ffee
commit 84bcc8115c
6 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package com.baeldung.hexagon;
public class ConstantTaxRateRepository implements TaxRateRepository{
private static final double TAX_RATE = 0.13d;
@Override
public double getRate() {
return TAX_RATE;
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.hexagon;
public class TaxCalculator implements TaxService {
private TaxRateRepository taxRateRepository;
public TaxCalculator(TaxRateRepository repository) {
super();
taxRateRepository = repository;
}
@Override
public double calculateTax(Double amount) {
return amount * taxRateRepository.getRate();
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.hexagon;
public class TaxFactory {
public static TaxService getTaxService() {
return new TaxCalculator(getTaxRepository());
}
public static TaxRateRepository getTaxRepository() {
return new ConstantTaxRateRepository();
}
}

View File

@ -0,0 +1,6 @@
package com.baeldung.hexagon;
public interface TaxRateRepository {
public double getRate();
}

View File

@ -0,0 +1,7 @@
package com.baeldung.hexagon;
public interface TaxService {
public double calculateTax(Double amount);
}

View File

@ -0,0 +1,9 @@
package com.baeldung.hexagon;
public class TestTaxUser {
public double calculateTax(Double amount) {
return TaxFactory.getTaxService().calculateTax(amount);
}
}