15-112 Agenda 18-June
- Quiz median: 81.5
- Looking forward:
- Today: OOP, hw13 assigned
- Tuesday: OOPy animations, hw14 assigned
- Wednesday: Dealing with large code bases + TP assignment
- Thursday: review
- Friday: in class final; no recitation
- Friday: TP Mentors assigned
- Final Exam Friday
- 80 minutes; in lecture
- Skewed towards content from after midterm1, but anything is fair game
- animation probably won’t be grid based (closer to hw14)
- More details later this week
- Content
- What do we currently do to keep code organized?
- Functions!
- Helper function!
- MVC
- What do we do when we want to store multiple things with the same properties (for example a bunch of circles in an animation)?
- Specially crafted lists
- This can be confusing: why is circle[2] the radius? Wouldn’t circle.radius be nicer?
- Solution: Object Oriented Programming (OOP)
- Objects (realizations) and Classes (general descriptions)
- Here’s how to describe a 112 student
- Here’s 3 actual students in 112
- Vocab: Objects are also called instances
- Syntax for classes + objects, and
__init__
- Defining your own methods
- Vocab: attributes (properties) and methods (behaviors)
- Vocab: method vs function
- Special methods
__hash__
__repr__
__str__
__eq__
- An example tying this all together with the
Student class
- OOP is great for modeling real world objects
- What about the relationships between these real world objects?
- For example: students are all humans. Dogs are all mammals. Etc.
- Inheritance:
- Allows us to model those real world relationships without repeating code
- Example of Human + Student class without inheritance
- Example of inheritance using Human –> Student –> 112 Student
- overwriting methods
super()
- type vs isinstance
- Not covered:
- class attributes
- static methods
- multiple inheritance
- Attendance Check: https://tinyurl.com/summer112att16