CS35: Data Structures and Algorithms

Week 02 Lecture Notes

Week 02 Tasks

Tuesday

Agenda

Our C++ programs so far consist of a sequence of statements that contain:

Object Oriented Programming

Objects are "blobs" that contain a bit of data and a bit of code

A Class is the blueprint of an object. It describes the attributes and implementation of the behaviors.
An Object is an instance of a class which (usually) holds explicit values for each attribute.

C++ Class Syntax

Example of a point class.

Topics covered:

Thursday

Agenda

Inheritance

We can create a hierarchy of types with base classes (or parent classes or super classes) that enforce a common interface and derived classes (or child classes or subclasses) that implement the interface and can contain additional features. In this course:

See examples with the Dog class and the Shape class.

Polymorphism

Polymorphism is the ability of a variable of type pointer to a base class to contain the memory address of an object of a derived class. This enables you to "forget" which precise type of object you are dealing with, and you can still call any of the methods declared in the base class. Virtual methods will still use the most recent definition of the method from the derived class.

However, calling a method that is unique to the derived class from a variable of type pointer to the base class will result in a compile error.

See examples using the Dog class and the Shape class.