getters and setters style

前端 未结 13 2624
猫巷女王i
猫巷女王i 2021-01-01 12:05

(Leaving aside the question of should you have them at all.)

I have always preferred to just use function overloading to give you the same name for both getter and s

13条回答
  •  情话喂你
    2021-01-01 12:15

    While Ed's comment is true, I do prefer actual properties over the setter/getter antipattern. When 1/3rd of the methods in your domain graph are dummy methods that have been generated by eclipse, there's something wrong.

    Without first class properties, however, I believe the antipattern makes the most sense.

    Furthermore, it makes code completion easier.

    obj.set (control shift space) for setters
    obj.get (control shift space) for getters

提交回复
热议问题