Coder Social home page Coder Social logo

python-p3-oop-putting-it-all-together's Introduction

Putting It All Together: Object-Oriented Programming Lab

Learning Goals

  • Create and instantiate classes in Python.
  • Build methods that perform functions tailored to their unique objects.
  • Use the property() function to create properties and validate input.

Key Vocab

  • Class: a bundle of data and functionality. Can be copied and modified to accomplish a wide variety of programming tasks.
  • Initialize: create a working copy of a class using its __init__ method.
  • Instance: one specific working copy of a class. It is created when a class's __init__ method is called.
  • Object: the more common name for an instance. The two can usually be used interchangeably.
  • Object-Oriented Programming: programming that is oriented around data (made mobile and changeable in objects) rather than functionality. Python is an object-oriented programming language.
  • Function: a series of steps that create, transform, and move data.
  • Method: a function that is defined inside of a class.
  • Magic Method: a special type of method in Python that starts and ends with double underscores. These methods are called on objects under certain conditions without needing to use their names explicitly. Also called dunder methods (for double underscore).
  • Attribute: variables that belong to an object.
  • Property: attributes that are controlled by methods.

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!

python-p3-oop-putting-it-all-together's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-p3-oop-putting-it-all-together's Issues

Lab too easy?

Canvas Link

https://learning.flatironschool.com/courses/6049/assignments/195257?module_item_id=439030

Concern

We can basically pass all the tests to this lab by give Book and Shoe an __init__ method and a turn_page and cobble method, respectively. Once we have these set up, all the other tests automatically pass, since python allows you to assign attributes freely. If this is meant to illustrate the ease of OOP with Python, then it's great.

But, this could also be an opportunity for students to practice using properties more. We don't have to make all attributes properties, but at least making a few of them properties could be good practice. It could also highlight the difference between non-properties, whose tests would pass as soon as the class is set up, and properties, which would need to meet certain requirements. Thoughts?

Additional Context

No response

Suggested Changes

No response

Putting It All Together Feedback

Canvas Link

https://learning.flatironschool.com/courses/6049/assignments/195257?module_item_id=439030

Concern

  • “Putting It All Together: Object-Oriented Programming Lab” –” Shoe in shoe.py says that the shoe has been repaired.” test is unclear. Doesn’t tell you what name or what to return. Unsure if this is intentional.
  • “Putting It All Together: Object-Oriented Programming Lab” – most the tests you need to write no code.
  • “Use the property() function to create properties and validate input.” This is never needed to pass the tests.

Additional Context

No response

Suggested Changes

No response

Test is commented out

In lib/testing/shoe_test.py in test test_requires_int_size one of the asserts is commented out.

def test_requires_int_size(self):
'''prints "size must be an integer" if size is not an integer.'''
stan_smith = Shoe("Adidas")
captured_out = io.StringIO()
sys.stdout = captured_out
stan_smith.size = "not an integer"
sys.stdout = sys.stdout
# assert captured_out.getvalue() == "size must be an integer\n"
assert not stan_smith.size

Module Not Found by Tests

Canvas Link

https://learning.flatironschool.com/courses/6049/assignments/195257?module_item_id=439030

Concern

The tests don't work as they do not recognize that the class containing the student's code is accessible by the testing files.

Additional Context

____________________________ ERROR collecting testing/shoe_test.py _____________________________
ImportError while importing test module '/Users/eleanorkelman/Documents/Python Phase 3 Labs/python-p3-oop-putting-it-all-together/lib/testing/shoe_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../../.pyenv/versions/3.8.13/lib/python3.8/importlib/init.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
testing/shoe_test.py:3: in
from shoe import Shoe
E ModuleNotFoundError: No module named 'shoe'

Suggested Changes

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.