Message |
Hi, Following on from http://www.paneris.org/webmacro/MessagePage?db=paneris&messageboard=166&id=47916 I have an issue which I would like to knock on the head and would appreciate comment. I've never got into the habit, like many people, of writing accessor methods for virtually everything. Reasons below but the nitty gritty of my point is that one could in theory use things like this instead: interface IntAccessor { void set(int v); int get(); static class Impl implements IntAccessor { private int value; void set(int v) { value = v; } int get() {return value; } } } (I haven't tried compiling it) Then: final IntAccessor fred = new IntAccessor.Impl(); And when you want to take advantage of the hidden implementation of fred you can subtype IntAccessor with an inner class. (i.e. member/local/anonymous that can access other features of the containing class). The reasons I avoid accessor methods if I possibly can is that I don't like to be distracted by the extra layer of coding. If I have an "object attribute" in mind then I want to code it as just an instance variable. Also, I never know where to put the important javadoc comments. I'm not sure of the disadvantages of the above (hence this message). I expect this might be incompatible with bean development and there is lots of software that assumes the same conventions. Anything else? Regards, Jim
|