What is the philosophy behind making the instance variables public by default in Scala. Shouldn’t making them private by default made developers make less mistakes and encourage composition?
What is the philosophy behind making the instance variables public by default in Scala.
Share
First, you should know that when you write:
nameandagearen’t instance variables but accessors methods (getters), which are public by default.If you write instead:
nameandageare only instance variables, which are private as you can expect.The philosophy of Scala is to prefer immutable instance variables, then having public accessors methods is no more a problem.