Skip to content

Instantly share code, notes, and snippets.

@ngallazzi
Created February 4, 2022 14:11
Show Gist options
  • Save ngallazzi/7c21c3144a2aacd227fc6ceb48483243 to your computer and use it in GitHub Desktop.
Save ngallazzi/7c21c3144a2aacd227fc6ceb48483243 to your computer and use it in GitHub Desktop.
Mastering refactoring - Introduce parameter object, final code
private fun printInvoiceHeader(header: InvoiceHeader) {
binding.tvInvoicePreview.text = header.toString()
}
data class InvoiceHeader(private val number: Int, private val date: LocalDate) {
override fun toString(): String {
return "INVOICE N° ${number}, ${formatter.format(date)}\n\n"
}
companion object {
val formatter: DateTimeFormatter = DateTimeFormatter.ISO_DATE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment