Putting It All Together: Object-Oriented Programming Lab (CodeGrade)

Close

Learning Goals


Key Vocab


Introduction

Object-oriented programming, or OOP, is an extremely useful programming paradigm in which we can organize our code according to how real-world objects might interact with one another. We can wrap properties/data and behavior up in classes, and then create instances, or individual "members", of those classes that can interact with one another.

One common misconception about OOP is that everything MUST model the real world. If we limit our objects to things in the real world, the limitations will start jumping out at us.

Imagine a phone call between 2 people. Sure, the PEOPLE are real, but what about the phone call? If we think about the phone call through OOP, we can model it too! A phone call has a caller and a receiver, a duration, and maybe even a cost_per_minute. In the real world, it's not a real thing, but in OOP IT IS!

In this lab, you will put together everything you've learned so far about Object Orientation in Python. You will be building out two classes, a Book class and a Shoe class.


Instructions

This lab is test-driven. You will write your code in lib/book.py and lib/shoe.py. Run the tests and work your way through the test errors one by one until you get everything passing.

You're also encouraged to look at the test files to see what the tests are expecting to be able to do with your classes. These tests won't force you to use everything that you've learned in this module- feel free to add any features that might be useful!

Note that there are separate test files for the two classes inside the testing folder. If you'd like to run the tests separately for the two classes, you can specify which test file to run:

$ pytest -x testing/book_test.py

or:

$ pytest -x testing/shoe_test.py

Remember that the optional -x flag makes your tests stop after the first failure- this setting is ideal for test-driven development!

Happy coding!