Hexagonal Architecture in Java - incorporated feedback
This commit is contained in:
parent
84bcc8115c
commit
a51abbab58
@ -1,11 +1,10 @@
|
|||||||
package com.baeldung.hexagon;
|
package com.baeldung.hexagon;
|
||||||
|
|
||||||
public class ConstantTaxRateRepository implements TaxRateRepository{
|
public class ConstantTaxRateRepository implements TaxRateRepository {
|
||||||
|
private static final double TAX_RATE = 0.13d;
|
||||||
|
|
||||||
private static final double TAX_RATE = 0.13d;
|
@Override
|
||||||
|
public double getRate() {
|
||||||
@Override
|
return TAX_RATE;
|
||||||
public double getRate() {
|
}
|
||||||
return TAX_RATE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,15 @@ package com.baeldung.hexagon;
|
|||||||
|
|
||||||
public class TaxCalculator implements TaxService {
|
public class TaxCalculator implements TaxService {
|
||||||
|
|
||||||
private TaxRateRepository taxRateRepository;
|
private TaxRateRepository taxRateRepository;
|
||||||
|
|
||||||
public TaxCalculator(TaxRateRepository repository) {
|
public TaxCalculator(TaxRateRepository repository) {
|
||||||
super();
|
super();
|
||||||
taxRateRepository = repository;
|
taxRateRepository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double calculateTax(Double amount) {
|
|
||||||
return amount * taxRateRepository.getRate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double calculateTax(double amount) {
|
||||||
|
return amount * taxRateRepository.getRate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package com.baeldung.hexagon;
|
package com.baeldung.hexagon;
|
||||||
|
|
||||||
public class TaxFactory {
|
public class TaxFactory {
|
||||||
|
public static TaxService getTaxService() {
|
||||||
|
return new TaxCalculator(getTaxRepository());
|
||||||
|
}
|
||||||
|
|
||||||
public static TaxService getTaxService() {
|
public static TaxRateRepository getTaxRepository() {
|
||||||
return new TaxCalculator(getTaxRepository());
|
return new ConstantTaxRateRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TaxRateRepository getTaxRepository() {
|
|
||||||
return new ConstantTaxRateRepository();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.baeldung.hexagon;
|
package com.baeldung.hexagon;
|
||||||
|
|
||||||
public interface TaxRateRepository {
|
public interface TaxRateRepository {
|
||||||
|
public double getRate();
|
||||||
public double getRate();
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.baeldung.hexagon;
|
package com.baeldung.hexagon;
|
||||||
|
|
||||||
public interface TaxService {
|
public interface TaxService {
|
||||||
|
public double calculateTax(double amount);
|
||||||
public double calculateTax(Double amount);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@ package com.baeldung.hexagon;
|
|||||||
|
|
||||||
public class TestTaxUser {
|
public class TestTaxUser {
|
||||||
|
|
||||||
public double calculateTax(Double amount) {
|
public double calculateTax(Double amount) {
|
||||||
return TaxFactory.getTaxService().calculateTax(amount);
|
return TaxFactory.getTaxService()
|
||||||
}
|
.calculateTax(amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user