Week 4 - Inheritance

Midterm Approaching

The midterm is next week and is an in-person test. You will need to make an appointment to take it. See the discussion board for more info.

Learning objectives

Upon finishing this week, you should be able to:

  • Use inheritance to extend classes
  • Identify appropriate uses for abstract classes
  • Describe how virtual functions differ from regular ones and enable polymorphism

Suggested pacing

Day 1

  • Inheritance
  • Do CPPLab Inheritance 1

Day 2

  • Virtual Functions and Polymorphism
  • Do VirtualFunctionCall WS

Day 3

  • Abstract Classes
  • Do CPPLab Inheritance 2
  • Check out Assignment

Day 4

  • Multiple inheritance and interfaces
  • OO Design
  • Do design activity

Online Activity Outline

Inheritance Basics

Inheritance is one of the fundamental tools for code reuse in Object Oriented programming. It allows one class to define itself as a specialized version of another class. Learncpp.com has a nice overview of why we care about inheritance that you might want to start with.

Read 15.1-15.5. In 15.4 don't worry too much about what a destructor is and why we need them * we will hit them later.

These videos offer some tips:

Read 15.9 and watch this video about the protected access modifier:

Do CPPLab Inheritance 1

Virtual Functions

Read 15.6-15.11

These videos touch on some of the key ideas:

Do the VirtualFunctionCalls worksheet from the Files area of elearn.

Abstract Classes

Do CPPLab Inheritance 2

Multiple Inheritance and Interfaces

Read learncpp.com 24.9 and the Interface classes part of 25.7. It is OK to skim the multiple inheritance page * our main goal it to understand what the pitfalls of multiple inheritance are and why many programmers avoid it. On the interfaces page, our main goal is to understand what an interface is, and why they are considered a safe way to use multiple inheritance.

These two videos briefly introduce the ideas of multiple inheritance and interfaces:

Design

This video introduces using inheritance to do class design:

Look in the files area for the Inheritance Design Worksheet. It is a quick pen and paper exercise based on OO Design video.