The OBJECTS of my affection...

This document was written by CS 290W TA Joshua Kay and was last modified

Okay, now we have our first Java program written, saved, compiled, and running, right? Well, we need to learn a little bit more about Object-oriented Programming, or OOP.

Let's start with Objects. Any physical thing is an Object. Look around the room. What are some Objects?

Desks, chairs, people, the floor, the door - these are all objects

Name some other Objects in the room...

Okay, we know what an Object is, but what does that mean in programming?

In OOP, we represent real-life physical objects, so as to simulate life.

What are some characteristics that Objects might have?

Well, a door has a doorknob - that is a characteristic of some kinds of doors.

Some doors are brown - that is another characteristic.

So, properties of an object are something like adjectives in English - what color is it, etc.

However, properties also refer to what the object possesses - how many legs does a desk have, etc.

So we can say that anything that describes an object can be thought of as a property of that object.

CLASSES - what are classes?

Classes are a general definition of objects. We use them in order to create a new object. You may think of them as cookie cutters from which the objects (cookies) come.

Example - we have a desk class. What does every Desk have in common? (excluding weird exceptions, please)

Desk - desktop material, legs, drawers, a type, etc...

So when we create a new desk - we have to decide - what is its desktop made of? How many legs does it have? How many drawers does it have? What type is it (Plastic, Wood, Metal)?

So say we create a new desk, and we call it myDesk. How do we represent myDesk's properties?

Generally, they are with the dot(.) prefix - as in myDesk.desktop, myDesk.type, myDesk.numberOfDrawers...

Let's try it again. Say we have a ball() class, and we create an object called basketball

Some of the properties would be that the basketball is orange, that it is round, that it is bouncy

basketball.color=orange, basketball.type=sphere, basketball.bounce=bouncy

golfball.color=white, golfball.type=dimpledSphere, golfball.bounce=kindaBouncy

Let's talk about Michael Jordan. Michael is bald. Michael is an NBA player (or was, anyway).

How would we access his hair (or lack thereof)?

nbaPlayer.michaelJordan.hair=none;

Let's think about how things are related. This is the essence of Object Oriented Programming.