tag:blogger.com,1999:blog-5638372.post110676569388683350..comments2023-10-10T05:22:56.347-05:00Comments on binkley's BLOG: Read-only properties in JavaBrian Oxleyhttp://www.blogger.com/profile/06617364377560752378noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-5638372.post-1106967600778260172005-01-28T21:00:00.000-06:002005-01-28T21:00:00.000-06:00David, I agree with you for business object as the...David, I agree with you for business object as the getters may well represent potential behavior, be lazy-evaluated, etc.<br /><br />But data transfer objects are, by definition, nothing more than data holders for communicating between program layers, so I am picturing public final fields as being like C-style structs but read-only.<br /><br />Your point is good to remind me to apply this idea only to the realm for which it makes sense, and not to try and show off with a clever trick. Sometimes clever tricks are very seductive for me.Brian Oxleyhttps://www.blogger.com/profile/06617364377560752378noreply@blogger.comtag:blogger.com,1999:blog-5638372.post-1106966658034257742005-01-28T20:44:00.000-06:002005-01-28T20:44:00.000-06:00I agree that blindly following the rule that "all ...I agree that blindly following the rule that "all fields must be private" is not necessarily always good. However, the advantage of forcing access via a getter is that it gives you the option of changing its implementation at a later date: e.g. if one of the fields is a Date object, then you might later decide to encode it as a long and simply modify your getDate() method to convert back to a date. Your getters might also do de-compression or decryption etc. I know it goes against the "You Ain't Going To Need It" principal, but it is something to consider all the same.David Kemphttps://www.blogger.com/profile/12250289605528269244noreply@blogger.comtag:blogger.com,1999:blog-5638372.post-1106930677186571552005-01-28T10:44:00.000-06:002005-01-28T10:44:00.000-06:00Gee, I wish I had posted that! What a polite and ...Gee, I wish I had posted that! What a polite and polished way to make that request.Brian Oxleyhttps://www.blogger.com/profile/06617364377560752378noreply@blogger.comtag:blogger.com,1999:blog-5638372.post-1106929746450735042005-01-28T10:29:00.000-06:002005-01-28T10:29:00.000-06:00Up until this point I have enjoyed the collegial n...Up until this point I have enjoyed the collegial nature of this BLOG and I would like to request that the individual posting obnoxious and useless comments please refrain from doing so. Your comments have become personal and no longer further the discussion.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5638372.post-1106912266584081152005-01-28T05:37:00.000-06:002005-01-28T05:37:00.000-06:00Whoever is making the obnoxious anonymous comments...Whoever is making the obnoxious anonymous comments, would you just calm down a bit? There is nothing wrong with making mistakes, we all learn from them. And this post is not even a post about mistakes but introduces an alternative technique to the more common approach of getter methods. There is nothing wrong with getter methods; it is more a question of style.Brian Oxleyhttps://www.blogger.com/profile/06617364377560752378noreply@blogger.comtag:blogger.com,1999:blog-5638372.post-1106901636578902802005-01-28T02:40:00.000-06:002005-01-28T02:40:00.000-06:00If you have to fix this stuff all day long then yo...If you have to fix this stuff all day long then you should either get another job without so many lamers, or fire their asses because they should go back to college.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5638372.post-1106783640623921242005-01-26T17:54:00.000-06:002005-01-26T17:54:00.000-06:00Getters and setters are never elegant, no matter h...Getters and setters are never elegant, no matter how you implement them. It leads to code that has more periods than a girls' locker room. Blech.<br /><br />Tell don't ask.<br /><br />http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html<br />http://www.pragmaticprogrammer.com/ppllc/papers/1998_05.html<br /><br />AslakAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5638372.post-1106777820047804752005-01-26T16:17:00.000-06:002005-01-26T16:17:00.000-06:00Well, read-only access doesn't necessary mean the ...Well, read-only access doesn't necessary mean the value is final/constant. Think of an internal state, for example, that can be read, but not be changed from the outside - but internally.<br /><br /><A HREF="http://www.blogger.com/r?http%3A%2F%2Fwww.gerd-riesselmann.net">Gerd Riesselmann</A>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5638372.post-1106774495830823912005-01-26T15:21:00.000-06:002005-01-26T15:21:00.000-06:00Well, yes, it is trivial. :-) But I spend time e...Well, yes, it is trivial. :-) But I spend time every day fixing such trivial problems in mediocre production code. Most unfortunate.Brian Oxleyhttps://www.blogger.com/profile/06617364377560752378noreply@blogger.comtag:blogger.com,1999:blog-5638372.post-1106771376461132202005-01-26T14:29:00.000-06:002005-01-26T14:29:00.000-06:00Well duh ! Were not amateurs you know dumbass ! Ho...Well duh ! Were not amateurs you know dumbass ! How long have you been around ?Anonymousnoreply@blogger.com