lundi 25 juin 2018

How to design a switcher for parameters in Scala?

Let's say I have an object which has a method foo that accpets OptionTypeV1.

Object Util {
def foo(option: OptionTypeV1)
}

Now, I have a new OptionTypeV2 along with existing OptionTypeV1, and I want to use them with Util.

I want to design a switcher that can switch the version of OptionType.

Object Util {

val optionV2 : Boolean = false

val OptionTypeVersion = optionV2 match {
    case true => OptionTypeV2
    case _ => OptionTypeV1
}

def foo(option: OptionTypeVersion)
}

Is this a good idea? Is there a better way to do it? Any reference?

Aucun commentaire:

Enregistrer un commentaire