Last active
August 3, 2021 12:05
-
-
Save PraveenMathew92/5ef597850cee8aa7dff171c5d9a1d7c5 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
data class Customer(private val firstName: String, | |
private val lastName: String, | |
private val age: Int) { | |
private val fullName = "$firstName $lastName" | |
fun isAdult(): Boolean { | |
return age >= 18 | |
} | |
fun getGreetingName(): String { | |
return if (isAdult()) fullName else firstName | |
} | |
} | |
class FrontEnd { | |
fun display(message: String) { | |
// code to display the message on the Frontend device | |
} | |
} | |
class DriversLicenseService { | |
private val frontEnd = FrontEnd() | |
private val driverLicenseApi = DriverLicenseApi | |
public fun greetCustomer(customer: Customer){ | |
val greetingMessage = "Good day, ${customer.getGreetingName()}" | |
frontEnd.display(greetingMessage) | |
} | |
public fun getDriversLicense(customer: Customer) { | |
if(!customer.isAdult()) { | |
throw CustomerNotAdultException(customer) | |
} | |
// code to get the driver license for the customer from external api (or a database) | |
return driverLicenseApi.getDriverseLicenseFor(customer.id) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment