Model a Farm Using OOP
00:00 The challenge is to create a simplified model of a farm. Also, keep in mind that there are many correct answers. So this is not going to be an exact solution, but there are going to be a lot of different solutions that are all correct.
There are specific requirements that you can use as a guideline. Keep in mind that they’re open to interpretation. You should have at least four classes: the parent
Animal class, and at least three child classes that inherit from
00:32 So that could be walking, running, eating, sleeping, or something that only, I don’t know, a horse would do. Keep it simple. Utilize inheritance. Make sure you output details about the animals and their behaviors.
How many can fit into a
Barn? Maybe you want to continue this. Maybe you feed the animals with other classes that could represent foods. Maybe there’s like this level of hunger, level of enjoyment that gets modified when you feed them.
01:36 The focus of this assignment is less about the class syntax, which you’ve already trained before in the review exercises, but it’s about software design in general. And again, this is highly subjective, so it’s intentionally left open-ended so that you get a chance to think about how you would organize your code into classes.
02:57 Now you can take pen and paper, or you can use a digital tool. It doesn’t really matter what material you use. The important thing is that you use your hands and that you can iterate over it often. Draw out your image of the code that you want to build, and I mean, do that before you actually write any code. So grab a pen and paper, sketch out a model of your farm. Identify what classes you want to build, which attributes they should have and which methods they should have.
03:24 Think about inheritance that can help you to prevent code duplication. And do this as often as you need before actually starting to code, just until you have a good mental model of what that farm abstraction is going to look like, because it costs a lot less energy to just draw a circle or a square and write a word there than to actually build that class.
03:48 If you do that beforehand, it just sorts your brain and gets you a mental model of the code that you’re actually going to build, which is super helpful, and it’s going to make your developing experience much nicer. So do that first.
04:02 Draw the idea of the farm that you want to model, and only start coding afterwards. I’ll also sketch my idea on digital paper in the next lesson. When you’re done sketching and coding your own farm, then continue with the next lesson and start to compare your solution and your process to mine. Have fun and see you there.
Become a Member to join the conversation.