Skip to content

Instantly share code, notes, and snippets.

@pawelpluta
Created January 28, 2021 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawelpluta/535c6cfeb09a109fb0f4915c5e7f9519 to your computer and use it in GitHub Desktop.
Save pawelpluta/535c6cfeb09a109fb0f4915c5e7f9519 to your computer and use it in GitHub Desktop.
Article: Tell Don't Ask: Raised Bed
public class RaisedBed {
private final RaisedBedId id;
private final List<Plant> plants;
public RaisedBed(RaisedBedId id, List<Plant> plants) {
this.id = id;
this.plants = plants;
}
public WateringResult waterWith(WaterValve waterValve) {
for (Plant plant : plants) {
WateringResult result = plant.waterWith(waterValve);
if (!(result instanceof WateringResult.SuccessfullyWatered)) {
return result;
}
}
return WateringResult.success();
}
// truncated other methods
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment