Do I have to make accessors for EVERYTHING?

Mime-Version: 1.0
Date: Mon, 24 Nov 1997 15:26:08 -0800
From: "Ted K." 
Subject: Re: accessors utility
Precedence: bulk

Folks, A month ago we discussed the question of when accessor methods should be created for instance variables. Apple Smalltalk has had a facility for "on-demand" accessor creation for many years. This facility is still in the image, but it is turned off. Here is how to turn it on:

Preferences setPreference: #autoAccessors toValue: true.

Here is how it works: When a selector is not understood during execution, the method Object.tryToDefineVariableAccess: is called. If the selector takes 0 or 1 args, and is the name of an instance variable of the sender, then the following choice pops up.

A wants to read from x in class . Define a this access message?

If the user clicks Yes, an accessor message is compiled. It can be either a getter or a setter (x or x: 3). The calling method is restarted, and execution proceeds. It also works for class variables.

My intention when I put this into the image, was that "on-demand" accessor creation only be used during the initial authoring of a class. It allows you to concentrate on building your class, and ignore the getters and setters. As you test your code, the system politely asks if you want to define the missing messages. Watch out for the ones that are used in cases you did not test!

I support the idea that some instance variables are implementation dependent in a class, and should not have accessors.

Enjoy it!


Ted Kaehler Walt Disney Imagineering, R&D (home) 3415 Cork Oak Way, Palo Alto, CA 94303 voice (650) 424-1070

All phone numbers in area code 415 south of San Francisco are converting to 650. Please change your address book for anyone in: Palo Alto, Stanford, Mountain View, Los Altos, Portola Valley, Woodside, Redwood City, Menlo Park, San Carlos, Belmont, Atherton, San Mateo, Foster City, Hillsborough, Burlingame, Milbrea, San Bruno, Daly City, Pacifica, Half Moon Bay, South San Francisco, (but not S.F. itself). 415 will not work for these cities after Feb. 1, 1998.

"More About Squeak..."
Home Page for How To Squeak

Last modified at 1/30/98; 9:43:01 AM
Other Links of Interest
College of Computing | EduTech Institute | GVU Center
Mark Guzdial | CS2390, Modeling and Design | STABLE