Right now in this very video
We are going to dive into the nuts and bolts and
Details of object-oriented programming. we're going to look at the syntax for writing an object in
Our main program and we're going to look at the syntax for how we define a class.
How it is we define the template the thing that will allow us to make objects. So what are we... we had this bouncing ball
I'm tired of that stupid bouncing ball
Not that the one I'm about to show you is really that much better, But
We're going to do something slightly a little bit different; We've got a bubble
We're going to think about making bubble objects.
Come on..
Computer
We have a bubble here is our little circle. It's floating up to the top of the screen. It's going to get to the top
It's going to stop so what do we have we wrote this program. It's much like the bouncing ball program
It's just got a bunch of functions. It has display, ascend, top. Display draws
it, ascend makes it move up, top checks to see if it's at the top and causes it to stop. Good
this is a non object-oriented programming
cut! OK, this is a non object-oriented program
We are going to turn it into an object-oriented program. How are we going to do that?
Ok so first thing first. We're going to sort of look at this backwards before we can make an object in our code
We've got to define a class, but let's actually look again at the syntax for using objects in our code
Well, we know
The general framework they're setup() and there is draw().
Set up and draw
We need to first declare a variable bubble b. This is pretty similar to something we've done before
int
x
This is the type
This is the name we have done something super duper exciting here
What we've done is we've actually in our minds made an entire new data type
We've really only looked at this idea of oh there's floats
There's ints maybe if you've kind of gotten a little further into Processing. Beyond this video
You might have even made something of type p image of type string
These are objects note the capital letter. That's just the convention
Lowercase here these data types are primitive data types. A primitive data type is a data type with just a single number of 0,
1, 2.3 something like that a
Object Data type is more complex. It's a collection of Data and
Functions, I think that's what I talked about the previous video that was last week when I made that you know as you can tell
By the different shirt that I'm wearing probably not that I don't afford the same shirt every day, but anyway um
ok so here we are
Bubble b, we have made a data type called bubble. Boy we are already several minutes into this video. Let's keep going ok now
When it comes time to go through
Into draw we want to act on that bubble
What did we call that? Ascend, we want it to ascend to the top of the window we want to display, we what to ascend.
this is what is informally known as as dot syntax?
We are doing something different. we are calling a function
But we are not calling a function
Just willy-nilly we are not just saying hey, you display. Hey, I said a top. We're saying no, no
No, this object display this object b dot display. We're calling the function on that
Object so anytime the object is b. That's the variable name the type. It's a type bubble
We're going to see how we define that type in a class in a moment
We are now saying we are acting on that. We are accessing that object through the dot. We're saying B
Dot that thought is like go inside and display the go inside and ascend.
We're saying send that B-but bubble B. Display that Bubble B
This is new here's the thing though if we were to run this code right now. It would say: "Meh"
Remember, it's like I don't know what that bubble is. It's null, no pointer exception
You really don't want to see null pointer exception
it is very upsetting so you could avoid them if you're at int x
Semicolon we declare this variable that was step one remember with variables back in our variable videos
What did we forget to do we forgot to initialize
Well with a with a integer we might just say x equals 10 with an object we use something a little bit funny
the syntax looks like this
equals new
bubble
New so this is something new that we haven't seen before put something new if it's the word new
okay, so
This is saying... what it really is... as if you almost literally translated
b is a new instance of a bubble object. b equals new bubble. that's what we're saying. new means make me a new object
This is actually executing something called the constructor, and we're going to see it in a little while drawing the greens for you
That we're going to see in just a little bit
We the constructor is the moment where the object is born it's the birth of the bubble object you just constructed
They should call that the birther. No that doesn't make sense the constructor.
Yeah, okay, so what this is this is where...
you know we're actually gonna go to the next video in a moment, but
This is where we are what we've got. Now is we know we have this prop... this program here that conceptually
Has this bubble floating up it has some variables and has some functions for doing that but it's not written in an object-oriented way
This is the guts of the bubble the guts of the bubble is all here in the main program
We want to move the guts to a class
So that in the main program. We can actually discuss the bubble itself the bubble object okay, so we're going to stop this video
We're going to go to the next one in the next one. We're going to write the class
You know interestingly enough you know, I'm trying to come up with an exercise at the end of these videos
There's not really one for here, but you could save yourself if this is
What, let's say you know, but hopefully maybe you know something, maybe you're just watching these videos for fun, I have no idea.
I can't imagine you're watching for fun. They're not that fun, but
imagine that you
Never knew anything about object oriented programming ever at all in your whole life and this is all you just learned which might be actually
the case you're in. Type this code into Processing copy, paste it from the thing we have below in our magical web video internet Web
Automatic thing we don't have yet and then try to decide
What would you how would you write a programming language so that how would you define the class for making a bubble?
How would you do that?
where would you put the functions where would you put the variables how would you do that sort of think that through because in the
Next video, we're going to see how it's done in Processing. Maybe you've just invented an entirely new programming language, and that's an exciting thing
Okay, and now this is the end of this video
it's the end