Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • this doesn't seem to offer anything substantial over points made and explained in prior 17 answers Commented Sep 8, 2014 at 10:12
  • 3
    The other answers talk about objects, interfaces and other languages paradigms. Which is fine, but it is not the central issue. Getters and setters are not just bad because they break some coding conventions, but primarily because you hardly ever encounter this behaviour in the actual model you are representing. This point tends to get lost in the discussion about the best coding practices. Commented Sep 8, 2014 at 10:42
  • 1
    On the contrary, many businesses do have the equivalent of get and set payroll processes. Granted, those processes are wrapped within authorization layers but there are getters and setters nonetheless. An employee's manager sets the employee's salary; it's not payroll that does that. Likewise, the manager's manager can get the salary information for all of their reporting employees. Commented Sep 9, 2014 at 13:48
  • 3
    If they are wrapped around authorization layers and restricted to certain external entities they are not getters and setters. I'm not saying don't have any method on the payroll department that changes the salary, but that method should align with the internal processes in place in the company itself. For example most companies set salary based on the employees contract, which is authorized by a manager. If the employee's salary changes a new contract is drawn up and a manager has to sign it. Therefore payroll should expect a contract object and some authorisation object to change pay roll Commented Sep 9, 2014 at 14:17
  • 4
    Or to put it another way, there is quite a difference between set_salary(new_salary, employee_id) and authorized_salary_update(employee_contract, authorising_manager). The process should model the internal business process Commented Sep 9, 2014 at 14:23