#Oriented Object Getters Setters

8 messages · Page 1 of 1 (latest)

barren quiver
#

Hello, I am new to Rust and I have developed a lot with object-oriented languages ​​and I would like to know if it is necessary to make getters for each field or to make these fields public. For example in Java we create a systematic Getter to access a value of an object.

ivory idol
#

I'd look into the getset library, if that's what you're looking for,

#

Getters are a good thing in the whole, to be able to view how encapsulated data is working, but setters aren't necessarily... usually you want to constrain the behaviour of your implementation, not have it be set arbitrarily...

fleet jacinth
#

Usually when we (computer science people) make getters and setters it’s less of a need and more of a should. This is because sometimes you don’t want anyone to be able to access a variable outside of the object ever. So I guess the answer is no, you don’t technically have to create getters and setters, but it could be helpful and good practice

barren quiver
#

So this rule applies even in RUST?

#

I read this on Google

ivory idol