EEKstream
July 24th, 2006, 02:45 AM
I have a little class. I have some variables which I would like to access from other classes. IS there any point in writing get/set for this? Why not only make the attribut public and skip the get/set method.
|
Click to See Complete Forum and Search --> : Get/Set neccessary EEKstream July 24th, 2006, 02:45 AM I have a little class. I have some variables which I would like to access from other classes. IS there any point in writing get/set for this? Why not only make the attribut public and skip the get/set method. ideru July 24th, 2006, 02:56 AM use it as a property, in your class.. you can set each variable property to accept or only return values. // am assuming here that you know how to make them into a property :) boudino July 24th, 2006, 03:19 AM Because of encapsulation, the fundamental property of OOP. There is big difference between the class's protocol - how it looks out, which methods exposes to outer world, and the class implementation - which fields it contains and how it deals with them. Nothing outside you class, including other your class, have not to take care about the class implementation. Believe us, this is not only academic excercise. If you would use getter/setter rather then public fields, you will avoid many problems in future. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |