Skip to content

Instantly share code, notes, and snippets.

@yanzm
Last active February 15, 2019 11:01
Show Gist options
  • Save yanzm/05d9d960ec68c97dc0abea4416572ac2 to your computer and use it in GitHub Desktop.
Save yanzm/05d9d960ec68c97dc0abea4416572ac2 to your computer and use it in GitHub Desktop.
//
// at domain layer
//
class FizzBuzzNumber(private val number: Int) {
fun expression(): String {
val isMul3 = number % 3 == 0
val isMul5 = number % 5 == 0
return when {
isMul3 && isMul5 -> "fizzbuzz"
isMul3 -> "fizz"
isMul5 -> "buzz"
else -> number.toString()
}
}
}
//
// at application layer
//
class FizzBuzz {
private var current = 0
fun next(): String {
current++
return FizzBuzzNumber(current).expression()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment