Classes and Objects
Object-oriented programming in Python.
Requires: Python
Introduces: Python objects and classes
Motivating questions:
- I have a complex program which has lots of duplicated code, is there any way to simplify it?
- How do I change the behavior of one part of my program without affecting the rest of it?
Lectures:
- Introduction (pdf, ppt)
- Objects combine functions with data to make both easier to manage.
- Objects add abstraction to help reduce duplication.
- They can also help programs to grow piece by piece over time.
- They also can make programs more complex, if overly used.
- Basics (pdf, ppt)
- A class defines a the behaviors of a new kind of thing.
- An object is a particular thing with particular properties.
- Methods are just functions that are part of a class.
- Member variables are just variables that are part of a class.
- Constructors are methods that are called when an object is created.
- Interfaces (pdf, ppt)
- Something’s interface is what it knows how to do
- Programming to interfaces makes it much easier to test/change/replace.
- Inheritance (pdf, ppt)
- One class can inherit methods and member variables from another.
- Inheritance makes it possible to reduce duplication of code
- Overriding allows a class to customize the behavior of methods it inherits.
- Overloading (under construction)
- Design (under construction)
- Quality (under construction)
Exercises: link
