0

I am fetching json data from a database formatted in the following way

{
    name:{
        type:string,
        value:'test',
    },
    age:{
        type:number,
        value:6,
    },
    hairColor:{
        type:color,
        value:'255,255,255',
    },
    font:{
        type:fontFamily,
        value:'Arial',
    }
}

So in my front-end I would have to check what the type is in some sort of switch statement in order to know what UI element I should render. This violates the open-closed principle becuase when I add a new type to my database I would have to go and modify the switch statement.

How could I deal with this?

anonymous-dev
  • 2,897
  • 9
  • 48
  • 112

1 Answers1

0

Why dont you use default for all other types. It should be in accordance with open-closed principle. For eg:

switch(type){
      case A:
       return $TRUE
      default:
       return $FALSE
}
r_batra
  • 400
  • 3
  • 14