-
-
Save pawelpluta/76cdb6bfea1d7e4ee9fa5e8530993916 to your computer and use it in GitHub Desktop.
Article: Tell don't ask - watering after refactoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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