Skip to content

Instantly share code, notes, and snippets.

@pawelpluta
Last active January 28, 2021 18:48
Show Gist options
  • Save pawelpluta/76cdb6bfea1d7e4ee9fa5e8530993916 to your computer and use it in GitHub Desktop.
Save pawelpluta/76cdb6bfea1d7e4ee9fa5e8530993916 to your computer and use it in GitHub Desktop.
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