-
-
Save pawelpluta/ab1f4423a66fea088802a1f07e1fa891 to your computer and use it in GitHub Desktop.
Article: The OOP has been explained wrongly to you - solution
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
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