[Bluej-discuss] How to call an accessor method in a different class?

Barry Brown barry at cs.sierracollege.edu
Mon Nov 19 09:36:21 GMT 2007


I think this is a great idea from a pedagogical standpoint. My BlueJ  
students seem to understand variable and parameter names. When the  
book introduces "this" in a constructor, it really throws the students  
for a loop. Up until that point, they have this idea that Java names  
are "global" and should be distinct within a class. Seeing a field and  
a parameter with the same name really gives them trouble and they have  
difficulty getting their heads around it.

I'm going to try using the "this" technique this coming semester.  
Problem is, the BlueJ book doesn't consistently use it. Can we get the  
authors to apply this principle?

-B

On Nov 18, 2007, at 12:24 PM, Lon Levy wrote:

> 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-)



More information about the bluej-discuss mailing list