Unit 8-07

Learning Outcome

At the end of this lesson, you will be able to:

  • understand and use inheritance in OOP

Review

  • OOP

Lesson

Key OOP Concepts

  • Inheritance
    • Super class and sub class
      • sub class gets all the "goodies" of the supper class

Activity

  • demo of inheritance for Bicycle class
    • the subclass inherits from the super class
class TandemBike(Bicycle)
    • add any new fields
self.__seats = 2
    • add the new field into the constructor
def __init__(self, gear, cadence = 0):
        # private fields
        
        Bicycle.__init__(self, gear, cadence = 0)
        self.__seats = 2
    • change any methods you need
      • remember to call the base, don't copy code!
def current_state(self):
        # returns the current state of the tandem bicycle as a string 
        
        # this varaible is local to this method
        return_string = Bicycle.current_state(self) + ' # of seats: ' + str(self.__seats)
        
        return return_string
    • video review of OOP Inheritance here

Daily Assignment

  • Add a second class, under your vehicle class called CubeVan
    • as you know a cube van has a large box on the back used to move things in
    • this box has a certain volume that is set when the van is built
    • normal vehicles do not have this kind of storage space (a trunk is different)
    • create a field that will hold the volume value
      • it should be set to 400 (for 400 cu. ft. )
    • you will also need to create a constructor and a ReadOnly Property in your class as well to handle the new property

Extra

  • work on weekly assignment

Homework!

  • read over Using OOP, Chapter 9
    • Computer Based Problem Solving
    • "Class Diagrams Again" & "Polymorphism"