Week 6: Object-Oriented Programming and Graphcs

Programming Styles

Up until now we’ve been using the Imperative programming style. We have treated data, like numbers and strings, as passive entities that can be manipulated by active operations, like addition or concatenation. This is the traditional way to think about computation where data and the methods for modifying that data are separate.

A more modern style of programming is Object-Oriented. In this approach, a program consists of a collection of objects and each object combines data with the functions that manipulate that data.

Objects know stuff and can do stuff.

This approach will often create virtual objects in a program that mimic real-life objects. For example, consider a bank account. What data does it maintain?

  • name

  • SSN

  • balance

What functions can it perform?

  • check your balance

  • withdraw money

  • deposit money

In OOP (Object-Oriented Programming), we would create a single type of object to represent bank accounts that combines both the data and the functions we need to perform.

This week we will learn how to use objects that have already been defined for us. Later in the semester we will learn how to create our own types of objects.

Graphics

A good example of OOP is creating graphics. So far, all of our programs have had a very simple interface. They have only been able to handle textual input and output. Now we will learn how to create graphical output such as pictures with colored shapes (lines, circles, rectangles, polygons), and how to use mouse clicks for input.

You should refer to the following notes on the graphics library for all of the different types of objects that you can use.