Last active
February 15, 2019 11:01
-
-
Save yanzm/05d9d960ec68c97dc0abea4416572ac2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// 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