Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the benefits of using properties internally?

Encapsulation is obviously helpful and essential when accessing members from outside the class, but when referring to class variables internally, is it better to call their private members, or use their getters? If your getter simply returns the variable, is there any performance difference?

like image 212
dlras2 Avatar asked May 21 '10 18:05

dlras2


1 Answers

There shouldn't be a significant performance difference, and the reason you stick to using the properties is because that's the whole point of encapsulation. It keeps all accesses of those private members consistent and controlled. So if you want to change the property getter/setter you don't have to think "do I need to duplicate the same functionality elsewhere in the places where I decided to access the private member directly?"

like image 53
Daniel DiPaolo Avatar answered Nov 10 '22 00:11

Daniel DiPaolo