Skip to content

Unit 3 ‐ Lesson 1

Robert Millikin edited this page Jun 3, 2020 · 5 revisions

This lesson is under construction.

Object-Oriented Programming

In Lesson 1, we learned about types (int, double, etc.) and functions. In Lesson 2, we created our own functions. Now we will create our own types.

A type is defined by a piece of code called a class. You can think of a class as a blueprint or template. An object is a concrete, individual variable of a particular type. For example, I can have a Shoe class which defines the Shoe type. The Shoe class defines what properties and functions a Shoe has or can do, respectively.

A particular Shoe is called an object, or an instance of an object. Different Shoes can have different properties, but not different kinds of properties; for example, all Shoes have a Color, but one Shoe can have a Color equal to Black where another Shoe can have a Red color, etc. In other words, the types of data stored within objects of the same type is invariant (Red and Black are both Colors), but the stored data itself can vary between objects.

Technically, int, double, etc. are not objects but are primitive data types. Objects function pretty similarly though, in many ways, though there are some important differences between primitives and objects which we will discuss. However, for now, you can think of them as generally the same thing.

Constructors

Object instantiation (i.e., creation)

Object Equality