ScalaStyle doesn't allow mutable variables. Sample code:
object Configuration {
var auroaDbConfig: AuroraConnectionParameter = null
def getConfigration() = {
val rootConfig: Config = ConfigFactory.load()
//for aurora configuration
auroaDbConfig = rootConfig
.as[AuroraConnectionParameter]("mdpApp.aurora")
//for spark configuration
val sparkConfig: SparkConnectionParameter = rootConfig
.as[SparkConnectionParameter]("mdpApp.spark")
//for cassandra configuration
val cassandraDbConfig: CassandraConnectionParameter = rootConfig
.as[CassandraConnectionParameter]("mdpApp.cassandra")
//for s3 configuration
val s3Config: S3ConnectionParameter = rootConfig
.as[S3ConnectionParameter]("mdpApp.s3")
}
}
Use Case : the ConfigFactory.load() is to be called only once
so placed it into a function which would be called once in the code & other variable are called as per required in the code
How do I refactor the code, so that variables are initliazed in the functions and called when and where required in the code