Board: Paneris java List

Subject

Accessor methods

Author

Jim Wright

Status

Date

15/09/2002 13:58

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

Paneris java List Board

 

Post Follow-up

Search This Board

 

Message Context:

Accessor methods Jim Wright 15/09/2002 13:58

    Accessor methods William Chesters 16/09/2002 12:32

        Re: Accessor methods Jim Wright 16/09/2002 14:55

            Re: Accessor methods William Chesters 16/09/2002 15:21

                Re: Accessor methods Jim Wright 17/09/2002 03:59

                    FW: Inheritance :) Tim at Work 17/09/2002 12:37

                    Re: Accessor methods Jim Wright 18/09/2002 11:50



Home -  News -  Reference Sites -  Members -  Partners -  Guidelines -  Philosophy -  Your Details -  Logout