How to do it...

  1. Implement the Printer class:
class Printer(val textFormattingStrategy: (String) -> String) {
fun printText(text: String) {
val processedText = textFormattingStrategy(text)
println(processedText)
}
}
  1. Add sample strategies:
val lowerCaseFormattingStrategy: (String) -> String = {
it.toLowerCase()
}

val upperCaseFormattingStrategy: (String) -> String = {
it.toUpperCase()
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.163.50