I have a singleton object, call it Bank
. Bank
has several methods, like addCustomer
, addRent
, etc. Each method has some parameters to do the job.
However, the precondition is that, some methods require me to check if that object, given by the parameter, exist, or does not exists (for example: when addCustomer
, check if customerID
is already in the database). So my class Bank
looks like this, let's simplify it.
object Bank{
//Some lists to store data here
fun addCustomer(customerID: String){
checkIfCustomerExist(customerID)
// Do something here
}
private fun checkIfCustomerExist(customerID: String){
// If customer is in list, throw exception
}
}
So far so good.
However, my program has many lists and required functions, so it has a lot of utilities methods to check if exist/not exist. Is it ok, or what should I do to follow the design principles? I plan to create another singleton object Verification and implement all these check methods there. What are your thoughts?
Aucun commentaire:
Enregistrer un commentaire