I am making a new class in PHP. I don't anticipate this class ever being extended. Should I bother with making class members private and implementing getter and setter functions?
Part of me thinks that this is just a big waste of time and only serves to bulk up my code.
The class is for a resume. I am writing it in code to demonstrate my coding style. The question is will an employer want to see getters and setters, or will that just clutter things up?
I don't want once again to repeat the argument that even that you don't expect inheritance now, you may still need it in the future, but they are still more reasons to use getters and setters:
Check out the __get and __set magic methods, it'll keep your code clean and you won't have to feel lazy for not setting variable scopel.
public function __get($name)
{
return $this->$name;
}
public function __set($name, $value)
{
$this->$name = $value;
}
Obviously you'd have more detail, but that will handle your accessors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With