samedi 2 septembre 2023

how do you design a function with 2 mutual exclusive arguments?

I would like to design a function that is handle the UI flow. When argument, shouldAddExistedName is true, it add the name from database (internal api) into one page. When argument shouldAddExistedName is false, it add the second argument name into one page. Based on UI behavior, 2 arguments shouldAddExistedName and name are mutual exclusive.

  • shouldAddExistedName is true, it omits the second argument, name. function is add the name from api to page
  • shouldAddExistedName is false, it handle some page and add the second argument, name to page. how of you design a function in this case 1: break out into small functions
    • addNamefromExistedName
    • addNametoPage(name)
  1. use multiple argument and one function with handling all case in the function
    • def addNameToPage(name: string, shouldAddExistedName: Bool): if shouldAddExistedName: # get name and add exist to page # return # Add name to page

Aucun commentaire:

Enregistrer un commentaire