Getters and Setters Are Evil or Not Evil?
2011-10-15 18:15
489 查看
在JavaLobby看到了Bozhidar Bozhanov的一篇文章Getters and Setters Are Not Evil,evil
or not evil, 这是个问题,set 和 get方法主要是为了适应JavaBeans规范产生的,Joshua Bloch也在他著名的书《Effective Java》中进行了含蓄的批评,不过迄今为止Java语言没有针对这个情况做很好的改善,使用Annotation标注的方式实现属性更是走入了一个极端,让简单的方式变得更复杂,是使用统一的方法命名方式还是在方法上加Annotation呢?显然是前者更直观,不得不承认C#在这个方面做的更好,属性的声明和实现在一个块中,减轻了程序员的负担!
Rémi Forax的属性提议就是模仿C#语言的(http://weblogs.java.net/blog/forax/archive/2007/01/property_reload.html),看起来还不错,能够节省不少代码,针对域对象和类似控件的Bound属性,只需要声明所有的Field就行了!
记住KISS原则:Keep It Simple and Stupid.
or not evil, 这是个问题,set 和 get方法主要是为了适应JavaBeans规范产生的,Joshua Bloch也在他著名的书《Effective Java》中进行了含蓄的批评,不过迄今为止Java语言没有针对这个情况做很好的改善,使用Annotation标注的方式实现属性更是走入了一个极端,让简单的方式变得更复杂,是使用统一的方法命名方式还是在方法上加Annotation呢?显然是前者更直观,不得不承认C#在这个方面做的更好,属性的声明和实现在一个块中,减轻了程序员的负担!
Rémi Forax的属性提议就是模仿C#语言的(http://weblogs.java.net/blog/forax/archive/2007/01/property_reload.html),看起来还不错,能够节省不少代码,针对域对象和类似控件的Bound属性,只需要声明所有的Field就行了!
记住KISS原则:Keep It Simple and Stupid.
相关文章推荐
- eclipse下maven打包失败(Please ensure you are using JDK 1.4 or above and not ......
- Where Are My Getters and Setters?
- Interview | Why are manhole covers round and not square or rectangular?
- Maven经典错误之一:Please ensure you are using JDK 1.4 or above and not a JRE
- Maven经典错误之一:Please ensure you are using JDK 1.4 or above and not a JRE
- Log and data area are not compatible because 'Restart position not found
- 关于laravel中key的错误cipher and / or key length are invalid
- FW - check whether tree is balanced or not - find the max and min of one tree- 2013年12月18日13:12:04
- YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. </HTML>/ 标签: yum 2014-05-26
- VMware Workstation and Hyper-V are not compatible. 解决方案
- sql关系型运算符优先级高到低为:not >and> or
- HTTP Error 404.2 - Not Found "The page you are requesting cannot be served because of the ISAPI and
- day17 oracle ----查询(select) ---(BETWEEN ... AND... ,IN(list), LIKE , IS NULL , AND ,OR, NOT) ---(字符 , 数字 ,日期, 转换
- HOWTO disable screensaver and powermanager while mplayer or other apps are running
- Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly
- Could not find action or result,There is no Action mapped for namespace / and action name hello_struts. - [unknown location]
- 转: Simple ASP.NET 2.0 Tips and Tricks that You May (or may not) have Heard About (一些简单的、你可能已经知道或者不知道的ASP.NET 2.0技巧)
- vmware和hyper-v共存问题 vmware workstation and hyper-v are not compatible VMware 和 Hyper-V 不能共存问题
- Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly
- /var/empty/sshd must be owned by root and not group or world-writable解决办法