I'm new in Java and I've completed the Head First Java and now Im reading Head First Object Oriented Analysis and Design.
Turns out that I was understanding everything but there is some piece of code that I would like to review with you because its still not so intuitive.
When the following call is made:
What does the door in BarkRecognizer mean? That means that it will pass the object to the BackReconiser class, is that right?
But what does this does exactly?
I simply cannot understand what this.door = door means and why the constructor have this. Is this only to NOT use inherence?
What is the name of the technique? How can I study more of this to understand better?
That is a standard idiom in constructors and setXXX methods. Remember that local variable hide fields, so in order to make the assignment apply to the field, you have to prepend this. to the variable name. Remember that = is pronounced “becomes equal to”, so you could pronounce
this.door = door; as
The field door becomes equal to the local variable door.
For the purposes of this post, parameters are a sort of local variable.
I understand the "this" and everything. But I'm under the impression that the code: is only to the Class BarkRecogniszer be able to call the methods of the class "DogDoor" that is passed by the line: Im right? If so, Im just under the impression that the same code might be used using inherence or other tricks.
I'm not sure if this is kind of a design pattern, or how can I study more about this pattern.