getters and setters style

前端 未结 13 2349
猫巷女王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:19

    If your getter is simply rate(), your compiler would complain that its a redefinition of your other rate symbol, provided you gave your field a good meaningful name like that. In that case you need to do something silly like name your member _rate or some other similar approach. I personally hate seeing/typing those underscores, so tend to go with the getRate() approach.

    This is obviously subjective and this just happens to be my personal preference.

提交回复
热议问题