-
-
Save le0nidas/9f802e631a63a410be6c9ad602d28067 to your computer and use it in GitHub Desktop.
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
// somewhere in the code | |
task.closeIfUnclaimed(createdBefore = LocalDate.of(2021, 1, 14)) | |
// task's better API | |
class Task( | |
initialStatus: Status, | |
private val createdAt: LocalDate | |
) { | |
var status: Status = initialStatus | |
private set | |
private val subscribers = mutableListOf<Subscriber>() | |
fun add(subscriber: Subscriber) { | |
subscribers.add(subscriber) | |
} | |
fun closeIfUnclaimed(createdBefore: LocalDate): Boolean { | |
if (status == Status.NotStarted && createdAt < createdBefore && subscribers.isEmpty()) { | |
status = Resolved | |
return true | |
} | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment