Originally posted by Namaste Sathi:
hi all,
could anyone please explain in simple way why the Getter and Setter methods are designed to get an access to attributes instead of making those attributes public and accessing them directly?
I would appreciate if you also could forward me a link that talks about concepts like this.
thanks.
The short answer is encapsulation -- a core concept of Object Oriented programming. If only methods can access your private data, then you can do a variety of things:
Change underlying data structureDelegate the access to another objectInstrument the access or perform other checksetc. Oh, and having accessor methods allows you to synchronize reads and writes to the data so you can prevent race conditions.
[ June 07, 2003: Message edited by: Richard Jensen ]