Are public variables faster than using getters and setters?

Viewed 2194

I am writing a custom physics engine for a game that I am making, my physics object class has tons of variables (distance, velocity, acceleration, mass, gravity, force, impulse duration etc....). Will creating a setter and getter function for each of these variables impact performance? (There will be at least 100 instances of this class at a given time)

Also should I create setters and getters? I heard public variables are really bad practice but there are a lot of variables, can this be an exception?

3 Answers

simply public variable violates OO design principles, but getter setter does not, That why we need to the user always getter and setter

Related