Smalltalk Report, June, 1993
Published online by Cambridge University Press: 04 August 2010
Why do I keep doing this? I keep bringing up the “should all variables be accessed through methods” debate whenever I see people taking a dogmatic position, that is, one that they don't explain. It wasn't until I rewrote the whole thing as patterns for the book that I realized the key issue here is communication.
I'm a little disappointed reading this now that I didn't try to write Direct Access and Indirect Access as patterns. That would have made the reasoning behind the options much more obvious. I guess I just wasn't ready to use patterns to address such fundamental questions. Now I don't even hesitate- I'm so pattern soaked now I can't help it.
Anyway, if this one bugs you, ignore it, all except the part about making accessors private by default.
A debate has been raging on both CompuServe and the Internet lately about the use and abuse of accessing methods for getting and setting the values of instance variables. Since this is the closest thing I've seen to a religious war in a while, I thought I'd weigh in, not with the definitive answer, but with at least a summary of the issues and arguments on both sides. As with most, uh, “discussions” generating lots of heat, the position anyone takes has more to do with attitude and experience than with objective truth.
To save this book to your Kindle, first ensure [email protected] is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.