Okay, um this, this is going to be a little bit of a tough one. Here we are we're going to...
begin talking about
object-oriented programming and the theory of object-oriented programming in a way.
And probably gonna remake this video, later but it's just going to live for
live with it for right now. So what I want to do in this video we're getting
into the nitty-gritty, and the nuts and bolts.
We're going to look at the implementation what it means to write a class to use objects to make multiple objects. Later
we will do arrays of objects. There's so much to come forward. But to start with, to begin with
we need to take a deep breath and just understand what are we trying to do with object-oriented programming?
Well okay. So in one sense
we're trying to understand a
computer program in the way that we think is somewhat about the world. And we've got one right over here.
We have this ball bouncing around the screen and we can see I've actually written this program already
using object-oriented programming. This is where
we want to get to. Understanding all of the pieces here by the end of this, of this this set of videos but
we can start with this here. What we did... what we're looking at here is we're seeing the manifestation,
the... an instance of a ball object moving around the screen.
What is a ball object? What Is the innovation of Object-Oriented Programming?
Well, our programs so far, have looked like this. We have setup(),
we have draw().
Right, that is the sort of framework for the flow of our program. What else do we have? We have a bunch of variables.
Up here, we can think of that as
the data
of a program. This is the data of a program. The x, the y, the xSpeed, the ySpeed, the color, the film, blah, blah, blah
We have the Functionality. What are the things that are happening? Something's moving, something's checking its edges, it's being displayed, it's...
exploding, its be... it's doing stuff. Happy, it's dancing! Right? We should have a dancing ball for a bouncing ball. But next time.
We have Functionality.
Move... I think I actually called it an update. We can see update in this. We have maybe a function called display.
You know displayBall. We had it in one of our most recent programs we wrote. We have...
Functionality
What Object-Oriented Programming does for us is it says: "Ok, we have data and we have functionality."
We want to put those things together.
We want to have an object that wraps the data for an entity, the functionality for an entity,
all together. What is that entity? Well that's what's up to you. Conceptually how
you organize the pieces of your program. If we were to make this palm, maybe there would be some paddles. So there would be
paddle objects and a ball object. Maybe there would be some
thing we need to sort of manage the whole game. The score, the player names. Maybe we'd have a game manager object that
has that data associated with it. So we're looking to take data and functionality and put them together.
We can think of this... One way to start thinking about this...
Is actually to think about you yourself or me myself as an object.
We are an object living in our world. What do we have? We have data.
For a human object. A human object. A human has data. Maybe a human has a height,
an eye color,
a sort of personality.
Right, there's so many things.
A way to...
Beard length.. and... whatever. As you can see that there's lots of data that can be associated to
describe those sort of aspects of a human being. A human being can
also do things. There might be Functionality. For example, I can eat, I'm actually right
pretty out of time to get lunch because I have some office hours appointments. I really
should be stopping this video but we've gone for four minutes, we're almost at the end. I can eat. I could sleep.
I could run. Right? There is Data and Functionality
associated with a human. What would it mean to package all those things up into an object so that we could add
human beings to our Processing sketch? Now that might be a little bit ambitious but but...
We could get there eventually. So this is the theory behind what we're doing.
We can start to see the syntax that looks like this. Now how does
Processing know what to do when to make a ball object or what to do when to update a ball object?
Well there's actually a sort of secret little tag here which I'll just flip to real quickly.
We'll look at this. This is all the code for the ball object.
This is like a mini program to describe
everything that's to do with a ball. There's variables from the ball. There's functions for the ball. That's what
we're going to get to in future videos. How do we write that.
But we should notice something about this that's pretty important.
And this is going to be very important to the next set of videos that
we're about to look at. The examples we're about to make.
There is this idea here.
What have I written up on the board here. I have not put a human being in board. There is no human being here.
What I have done is given you a template for making a human being. This is the cookie cutter. The cutter to
cut a human being out of the
stuff that would make a human being. Right? But there is something.. this is the
concept of what it means to be a human being. Then there is right here. The human being, him, or herself.
Right? I am an instance of a human being object. I am a human being. I am human.
Ah don't ah... Whatever. Anyway this is what it means to be a human being.
I know it seems silly that I'm going on and on about this but this is actually quite important. We have this
thing in Processing we're going to see, which is called a class. A class you can think of as the template.
Right, a cookie cutter is a template for making a cookie.
A cookie which I could eat. Yum, yum, yum. Is the cookie itself. This is quite important.
We need to write the class. We need to write the template
for what it is to make a ball so that we can have an actual instance of a ball object in our program. So the
class is the template. The object...
is the thing
itself.
So this is where we're going and I think in the next video or if I look at my outline correctly. What
we're going to do is learn how to write a class. We're going to learn how to write a class so that
we can make an object in our program. What we're seeing here right now is the object
itself, the instance of a ball. What's on this mysterious
second tab here is the class. The template. The things don't exist unless
we use them. The template is what defines what it Is to be a ball
bouncing around the screen in
Processing. So this is what we're looking to do. This is what we're hoping to do in these next set of videos.
Think about this. I don't really have an exercise for this. Ah! Here's an exercise.
Take something you've done in a Processing sketch and
try to write as a list, just write for yourself what is the data associated with it.
What is... what are the functions associated with it. So design your template without code. You could do this with pencil and paper and if
you want you can even sort of
imagine what it would be to type the program like this. Without knowing what each piece of the syntax does. You can kind of
look at this and understand its structure. Okay so in the next video, we will actually look at writing the class itself.