[Bluej-discuss] How to call an accessor method in a different class?
Lon Levy
lxl at oregon.k12.wi.us
Sun Nov 18 20:24:06 GMT 2007
Hi Aryeh,
Is using this. overkill? Yes, if we are talking about professional coding. With my high school students, I, like Dr. Bloch, require that they use this. or otherObj. for all instance fields and method calls. The first set of lessons for my AP students includes writing a class with an overloaded constructor, where one constructor calls another with this(stuff ...). Understanding what objects are and how they relate to classes becomes easier for my kids by this bit of overkill.
In terms of bad habits, I don't think so. For one thing, while it is nonstandard, no competent Java programmer should be thrown by an extra this. Second, no IDE should reject the code and the compiler shouldn't either. Finally, this is the sort of "habit" which a programmer can lose easily enough while learning to be lazy later. 8-)
Regards,
Lon.
Lon Levy, MS-CSEd
Computer Science Teacher
Volunteer Computer Club Advisor
Oregon High School
608-835-1316
LXL at oregon.k12.wi.us
cs at levytree.net
non somnos requiem
>>> "Aryeh M. Friedman" <aryeh.friedman at gmail.com> 11/18/07 9:54 AM >>>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
>
> This might be a little easier if the first question or two had less
> magic in them -- in particular, the automatic "this" shortcut. When
> I teach this stuff, I expect EVERY field reference to be of the form
> OBJECT.FIELDNAME, and EVERY method call to be of the form
> OBJECT.METHOD(ARGS); if the field or method is in the current object,
> my students are expected to use "this" explicitly as the OBJECT.
a) overkill?
b) teaches bad habits (i.e. non-standard style)
- --
Aryeh M. Friedman
More information about the bluej-discuss
mailing list