Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Add a Non-Public Attribute

00:00 Previously, I just revised my draft and I said, I’m going to kick out .enter() and .exit(). So I will not actually implement .enter() and .exit() on farm locations, but instead I’m going to make sure that I can do the movement of the animal from the .move() method inside of the Animal class.

00:18 And here we are on line 64 for me is the .move() method where there’s nothing implemented yet, but I already have access to instances, an instance method, and then also as a second attribute, .location.

00:31 I want to be able to store the location that an animal currently is at. And for that, I will add a new instance attribute that I’ll call self._location. Again, I’m making this a non-public attribute because, well, I don’t really necessarily want this object, the FarmLocation object, to be visible directly to a user.

00:54 I’m not a hundred percent sure I’m going to stick with that, but that’s kind of my feeling for now. I want this to be a non-public attribute. I can always change it later if that turns out not to make sense.

01:04 And I’m going to initialize an Animal object with self._location set to None. So it starts off being, I guess, nowhere.

01:13 We’ll figure out what that exactly means. But eventually this is going to hold an object. It’s going to hold a FarmLocation object or one of its child classes, a Barn or a Field, in this case.

01:26 Let’s see how we can implement that in .move(). Let’s draft up what do I need to keep track of here because there’s a couple of things going on. Now, I’m assuming that this location argument that I’m passing into .move() is going to be the reference to a location object, either a Field or a Barn in these cases, but could be any child instance of a FarmLocation.

01:49 And I need to keep track of the animals list in that object. So I’m going to have to step through that object to make sure that they stay up to date as well. It’s a lot going on here.

02:00 So I’m just going to start off by taking a couple of notes what I can think of that I will need to do here. I need to .exit() from a location if the animal is in.

02:12 I need to .enter() into a location if it’s not. I need to make sure that I don’t .enter() if it’s full

02:25 and don’t .enter() if the animal is already there.

02:34 So these are a couple of ideas I have of what I think I’m going to have to implement in the .move() method. Let’s go ahead and start tackling them in the next lesson.

Become a Member to join the conversation.