Skip to content

Instantly share code, notes, and snippets.

@pawelpluta

pawelpluta/Laundry.java Secret

Last active Oct 8, 2020
Embed
What would you like to do?
Article: The OOP has been explained wrongly to you - solution
class Laundry {
private final List<LaundryElement> allLaundry;
private Laundry(List<LaundryElement> allLaundry) {
this.allLaundry = allLaundry;
}
static Laundry of(List<LaundryElement> allLaundry) {
return new Laundry(allLaundry);
}
List<LaundryElement> asList() {
return unmodifiableList(allLaundry);
}
Laundry with(LaundryElement newLaundryElement) {
List<LaundryElement> updatedLaundry = new ArrayList<>(allLaundry);
updatedLaundry.add(newLaundryElement);
return Laundry.of(updatedLaundry);
}
Laundry withOut(List<LaundryElement> removedElements) {
List<LaundryElement> updatedLaundry = new ArrayList<>(allLaundry);
updatedLaundry.removeAll(removedElements);
return Laundry.of(updatedLaundry);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment