Object Oriented Programming
Reading
Chapter 17.
Key ideas
From chapter 17
- An instance of a class is mutable.
- A mutator method is a method of a class that changes the values of one or more instance variables.
- Shallow equality occurs when two variables refer to the same object in the computer’s memory. The Python keyword
is
tests for shallow equality. - Deep equality occurs when either there is shallow equality OR two variables refer to objects that contain the same underlying (significant) values.
- The method
__add__(self, other)
can be defined so that the operator+
can be used.
Additional resources
In this course, we did not cover inheritance, which is a very useful feature of object oriented programming. If you would like to read about it, check out this short reading. You can also watch the lectures from the Spring 2019 CSCI 127 course which address inheritance:
You can download the dungeons.py file for an example of inheritance.
If you’d like to test your knowledge, here is an example question using inheritance.