Skip to content

Instantly share code, notes, and snippets.

@pawelpluta

pawelpluta/Watering.java Secret

Last active Jan 28, 2021
Embed
What would you like to do?
Article: Tell don't ask - watering after refactoring
public class Watering {
private final RaisedBedRepository raisedBedRepository;
private final WaterValveRepository waterValveRepository;
public Watering(RaisedBedRepository raisedBedRepository, WaterValveRepository waterValveRepository) {
this.raisedBedRepository = raisedBedRepository;
this.waterValveRepository = waterValveRepository;
}
public WateringResult perform(WateringCommand command) {
// cut out: getting raised bed with plants and wattering bed
return waterBed(raisedBed.get(), waterValve.get());
}
private WateringResult waterBed(RaisedBed raisedBed, WaterValve waterValve) {
WateringResult successfullyWatered = raisedBed.waterWith(waterValve);
raisedBedRepository.save(raisedBed);
waterValveRepository.save(waterValve);
return successfullyWatered;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment