开发者

Method naming conventions. Should the method be named getX(), if the there's no corresponding setX()?

开发者 https://www.devze.com 2023-01-20 22:40 出处:网络
Say I got an Employee class that has a hire date data member. This member 开发者_如何学运维only get set one time only and it is constant too. So it\'ll get initialised when the object is created.

Say I got an Employee class that has a hire date data member. This member 开发者_如何学运维only get set one time only and it is constant too. So it'll get initialised when the object is created.

If I want the class to have a method that returns the hire date, what's better:

getHireDate();

Or just:

hireDate();

Am I thinking too much :D ?


Just

getHireDate();

is fine. It doesn't need a 'set' method to be proper OO.

Edit: if you haven't yet, read some Java Coding Style docs... they're simple enough, and standard coding conventions make everybody' life easier. I just found this: Java Programming Style Guidelines. Good reading.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号