I am start working on existing Scala and Akka project. I say Scala classes, some fields making them as private and providing getter and setter methods in different way. why like that you can make it as public also right.
I say in my project
Why this way:
class Person() {
// Private age variable, renamed to _age
private var _age = 0
var name = ""
// Getter
def age = _age
// Setter
def age_= (value:Int):Unit = _age = value
}
So you can get same feeling like public:
person.age = 99
Why not this simple way?
class Person() {
var name = ""
var age = 0
}
// Instantiate a person object
person = new Person()
// Print the object's age and name properties
println(person.age)
println(person.name)
// Set the properties to different values
person.age = 34
person.name = "Dustin Martin"