Test Move Method
an instance of a
Barn that holds only one animal. Also an instance of a
Field that holds ten animals. Okay, I have a
Barn, and a
Field all initialized, and now I should be able to move around and test out the new
But that doesn’t mean you can’t go off on a side quest. Investigate my buggy
.move() method, and propose a fix in the comments. I’ll redeem myself with a bugfix lesson just before the end of this course.
The interesting thing that you’re doing here is that you’re using some sort of an element of composition, I guess. This is called aggregation, because you’re not technically composing an object from another object. Well, I guess
Animal has some sort of composition in there because we have a
._location that is going to be the
Location object, and here we have in the
.animals, we see a form of aggregation where you’re adding
Animal objects to an internal list of the
FarmLocation object or its children.
04:35 Great. I’m going to clean up the comments here just to make this a bit cleaner. Do you want to print a message when I remove it? Not really. I’m just going to inform when it enters the location.
Become a Member to join the conversation.