Summary

Resources

oop-coffee-machine-start

Steve Jobs in 1994: The Rolling Stone Interview

https://drive.google.com/file/d/1DoECJcgYYwyZFBIBH8CW31woaf50FGbz/view?usp=drive_link

https://drive.google.com/file/d/1q4IuRV1yqrO4w3EVZ6plADTXNMTXR3m5/view?usp=sharing

https://drive.google.com/drive/folders/1fCzPHyUpACFk-RGAxMsXwd6ooIyuBrcS?usp=drive_link

Notes\ Code

Steve Jobs explained why OOP is so great by saying imagine that you go on a trip to a foreign country and when you arrive your shirt is dirty. What do you do? You’re in this unfamiliar city, you don’t know where to find a laundromat, you don't have the right currency, and don’t speak the language. Then you realize you’re staying at a hotel and the receptionist could help, so ask if they can do anything bout getting your shirt clean. The receptionist says it will be no problem they’ll handle it for you and what you get back is a nice clean shirt! This is like OOP in that all you have to do is get the object hotel and call its method, dry_clean() and it does all the messy stuff for you.

Lets go back to our coffee machine from yesterday, and test our knowledge of OOP by making a new version using the same requirements. For the exercise we are given new starting files that have the code written for us like an external library. We just need to build the program again using OOP in main. Lets do it.

from menu import Menu
from coffee_maker import CoffeeMaker
from money_machine import MoneyMachine

menu = Menu()
coffeeMachine = CoffeeMaker()
pos = MoneyMachine()

plugged_in = True

while plugged_in:
    coffees = menu.get_items()
    choice = input(f"What would you like? ({coffees}): ").lower()
    if choice == "off":
        plugged_in = False
    elif choice == "report":
        coffeeMachine.report()
        pos.report()
    else:
        coffee = menu.find_drink(choice)
        if coffeeMachine.is_resource_sufficient(coffee) and pos.make_payment(coffee.cost):
            coffeeMachine.make_coffee(coffee)

Transcript

As we begin working more with objects, their attributes, and methods, we'll start to understand why programmers find them so useful. The late Steve Jobs, though not a programmer himself, gave one of the best explanations of Object-Oriented Programming (OOP) through a brilliant example.