Strategy design pattern.
This commit is contained in:
parent
5332703017
commit
bd5cc6ff7a
@ -0,0 +1,20 @@
|
||||
package pl.amu.edu.demo.logic;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
import pl.amu.edu.demo.data.Housing;
|
||||
import pl.amu.edu.demo.data.WeWillStealYourFlatCheckResult;
|
||||
import pl.amu.edu.demo.providers.AverageQuoteProvider;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
|
||||
public class ApartmentHousingStrategy implements HousingStrategy {
|
||||
|
||||
AverageQuoteProvider provider;
|
||||
|
||||
@Override
|
||||
public WeWillStealYourFlatCheckResult checkEligibility(Housing housing) {
|
||||
return WeWillStealYourFlatCheckResult.ELIGIBLE;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package pl.amu.edu.demo.logic;
|
||||
|
||||
import pl.amu.edu.demo.data.Housing;
|
||||
import pl.amu.edu.demo.data.WeWillStealYourFlatCheckResult;
|
||||
|
||||
public class HouseHousingStrategy implements HousingStrategy{
|
||||
@Override
|
||||
public WeWillStealYourFlatCheckResult checkEligibility(Housing housing) {
|
||||
return WeWillStealYourFlatCheckResult.NOT_ELIGIBLE;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package pl.amu.edu.demo.logic;
|
||||
|
||||
import pl.amu.edu.demo.data.Housing;
|
||||
import pl.amu.edu.demo.data.WeWillStealYourFlatCheckResult;
|
||||
import pl.amu.edu.demo.providers.AverageQuoteProvider;
|
||||
|
||||
public interface HousingStrategy {
|
||||
|
||||
WeWillStealYourFlatCheckResult checkEligibility(Housing housing);
|
||||
|
||||
static HousingStrategy getInstance(Housing housing, AverageQuoteProvider provider) {
|
||||
return housing.isApartment ? new ApartmentHousingStrategy(provider) : new HouseHousingStrategy();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package pl.amu.edu.demo.logic;
|
||||
|
||||
import pl.amu.edu.demo.data.Person;
|
||||
import pl.amu.edu.demo.data.WeWillStealYourFlatCheckResult;
|
||||
import pl.amu.edu.demo.providers.AverageQuoteProvider;
|
||||
|
||||
public class WeWillStealYourFlatProduct {
|
||||
|
||||
private final AverageQuoteProvider provider;
|
||||
|
||||
public WeWillStealYourFlatProduct(AverageQuoteProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public WeWillStealYourFlatCheckResult check(Person person) {
|
||||
var strategy = HousingStrategy.getInstance(person.housing, provider);
|
||||
return strategy.checkEligibility(person.housing);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user