Alex Rivera | Logout

Do getters and setters impact performance in C++/D/Java?

Asked 2009-07-10T14:47:42.317
35

This is a rather old topic: Are setters and getters good or evil?

My question here is: do compilers in C++ / D / Java inline the getters and setter?

To which extent do the getters/setters impact performance (function call, stack frame) compared to a direct field access. Besides all the other reasons for using them, I would like to know whether they are supposed to affect the performance besides being a good OOP practice.

Edit
Report

1 Answer

3

A getter would be required for certain members in some cases. However providing a getter and setter for each data member of a class is not a good practice. Doing that would be complicating the class's interface. Also setters would bring in resource ownership issues if not handled properly.

answered 2009-07-10T15:41:34.080

Your Answer