Why OOP?
Making a very visual explanation to why use OOP with some side notes. The goal is to visualize the idea of why we use OOP. With live feedback from our students.
Video Transcript
00:00All right, so I'm just gonna create a small ball and I and by the way, I'm just clicking on shift and by the way
00:05One of the most anything you do in flash
00:08I think we've talked about in the past but really a great shortcuts to remember is shift out and
00:13Command and really just check them out and see what they do every every different tool
00:17It does something else for them
00:18But basically when you click on shift it usually makes things stay perfectly aligned
00:23So like if I create a circle without using the shift
00:25It's just gonna be wherever my mouse is
00:27But if I press on shift it's gonna force it to be a perfect circle and it's true for a lot of things when you click
00:32On shift so just try clicking shift see what happens same thing for alt without alt usually is in charge of duplicating things
00:39So if I have something
00:42Selected if I just move it. That's one thing
00:44But if I press on the alt or the option button and I drag then I'm gonna duplicate it
00:50Now before we duplicate which we are gonna duplicate in a second. I have her a ball. I created a ball
00:55Let's imagine that it's a real ball in the real world now this ball
00:59Right now is that really a ball right because I just drew it on the stage
01:03It's not really a ball
01:04but if I actually put it into a movie clip and I'm gonna convert it into a symbol and
01:09I'm gonna turn it into a movie clip and I'll just call it ball
01:13Now now I have a real ball
01:15Why is it what why did that make the difference when I only drew it?
01:18It was just basically I would say like a sketch of a ball as soon as I put it into a movie clip now
01:23It's contained into an object now that object you could even almost say that it's like a barcode now
01:28It has like a now it has like a reference now when you go into the library in your window
01:34Library now you're gonna find your you will get or why am I saying now?
01:38You're gonna find that ball
01:40Previously if I just took another ball and I let's say I drew it in a different color
01:43I just drew a sketch and that sketch is not really it doesn't really exist so I could draw your a ball
01:50I could click on my shift again to make it perfect
01:52But it will it won't come up in the library and it won't come up in the library until I actually say okay
01:57Now I'm done with creating my sketch
02:00Now I want to add it to my library by adding it to my library
02:03What why would I want to add it to the library?
02:05It's exact same thing as adding a barcode as soon as you add a barcode to something now
02:10You could start selling it you could start tracking it you could start spreading it around the world and in programming
02:15It's not that far not that far away or in flash in general
02:19We didn't even get to the concept of classes, but the whole basic idea of classes is really really similar
02:25So we basically first we're going to create the blueprint which is this is our little drawing then we're basically saying okay
02:31We have our thing now. We want to give it a name
02:33We want to give it a reference in our library
02:35So we're going to convert it into a symbol and then we turn it into a movie clip and by converting it into a movie
02:41Clip we're going to call this let's say ball 2
02:45By converting it into a movie clip now
02:47We have a reference in our library by having a reference in our library now
02:51we could delete obviously these elements and now we could drag them along and
02:56These references will get just
02:58Automatically get recreated again and again no matter how many times we put it on the stage
03:02So far easy enough, and you might already know this in your pry thinking well, then I know this
03:07Why are you saying this and what does this have anything to do with object-oriented programming well?
03:13The reason why I'm saying this a movie clip in a library
03:17Even without you knowing it is actually a class. It's a visual class now. How do I know that now?
03:24Anything that's a class a class is basically a blueprint and these are our blue
03:29Blueprints as soon as we throw them onto the stage are they the library asset no the light
03:35It's it's a duplicate or a
03:37You would say an object of the library
03:40Thus if I if I try to go into my library asset
03:44And I double-click in and I'm gonna take my green ball and just notice what I'm doing
03:48I'm gonna destroy the ball by just like squishing it
03:51And now I'm gonna go out of the ball as soon as I go out of the ball all the references changed and the big
03:57Question is why and I'm gonna throw this question to you guys before I answer it because I want to see that you guys are
04:01with me now
04:04Right, I'm changing the blueprint exactly so thanks Danny, so I'm changing the blueprint thus by changing the blueprint
04:11I'm changing every single
04:12Instance of that blueprint every single instance of something that was created from that blueprint and that that makes sense, right? So
04:21Just as much as that makes sense. It's just as much as if I sell
04:24If I sell a software and I make a software update and all the different applications throughout the world that have that update are
04:30Automatically updated the idea of classes are not that far away from that a lot of times
04:35We want to use something and you reuse something you want saying that's going to be reusable now
04:40We're used to because we're humans and because we deal in our life with things that are tangible
04:45We deal with cups. We deal with microphones. We deal with objects. We deal with things that are there in front of us
04:51We do deal with keyboards now this keyboard. I didn't invent the keyboard
04:55All I did is I went to the store and I bought it someone else created that
04:59Blueprint that idea and then they manufactured it so I could now buy and there's millions of these keyboards all over the world
05:05or millions of the bottles of water that I have right here and the same deal happens also with our ball instance as
05:11Soon as we created it now we could start mass producing it
05:15We could now use it instead of retyping each time something or instead of reusing something without without having a central logic
05:23Now it might be a little bit complicated and beginning just to get into the syntax
05:27no one ever said that the syntax is easy, but the whole concept of
05:32the whole concept of basically taking things from the real world and
05:37manufacturing
05:39Obviously if I wanted to sell bread
05:41Let me just ask this and this is a very obviously a little bit of a rhetorical question and if everyone please answer
05:46Because it'll be nice to see that everyone's with me on this one now
05:49I have two ideas and tell me which one is a better idea. I
05:54Want to sell bread now?
05:56I could or one sell loaves of bread that are ready and charge for it a dollar or
06:01I could sell a bag with flour eggs water
06:05Sesame seeds and whatever other products I believe bread would have and I could just send that bag and just sell that back to people
06:15What do you think will sell better the loaf of bread or the bag with the ingredients of the bread in a supermarket?
06:22They'll be the same price both
06:28pre-made bread
06:30exactly and
06:34Exactly because you did the work for the customers things that you really you guys are you guys are going along with the with the line
06:40I thought that I'm kind of showing you here. Is it more complicated to create the bread?
06:45Definitely it when we're going to be doing the object oriented programming
06:48It definitely is more complicated for us when we're building that object because we have to think how does bread work and we might
06:55Have all these different configurations. Maybe some like their bread with raisins
06:58Maybe some like their bread with whatever they like it and it makes our life a little bit more complicated
07:04But after we created that loaf of bread
07:07Now we could just use that bread as a bread and for now on we don't even care what the ingredients are because now it's a
07:13Bread and if you asked a lot of people to have no idea what the ingredients or bread are or our ice cream or whatever
07:19It is right. There's a lot of ingredients. We have not even what they are why because they're recreated after they're created
07:24We don't even care what they are because we know that they work and that's exactly how object-oriented programming works in its core
07:31And when you when you start thinking object-oriented coding
07:34Really the first question you want to ask yourself is is there something that I could take that's complicated or that has a lot of a
07:41Lot of operations a lot of things that are going on into it. Is there a logical cluster?
07:46Is there a logical group that could hold it together?
07:48So from now on I could just only talk to it as if it's only that one thing and that's really where
07:53object-oriented programming is so brilliant because
07:57Yeah, it's harder to code. But after you build that little small component after you build the cat
08:03That's it. You have a cat from now on you don't have to call it that
08:08Mammal with hair that meows and that sleeps 16 hours a day because now it's a cat
08:13so from now on you could treat that really really complicated thing as one word why because you just created an object for it and
08:21That's exactly the minds that you want to have and really that's the most important thing
08:25You need to know an object-oriented coding all the rest all the rest an object-oriented programming is is bullshit
08:31There's a lot of methods
08:33There's a lot of ideas a lot of a lot of things but end the day
08:36The basic idea and the only idea that should be on the top of your head while you're coding and you're doing object-oriented programming is
08:44Could I create things that are logical could I create logical clusters?
08:48That are logical in my head that hopefully will be logical for others as well and could I start reusing them the more of these?
08:56logical groups of
08:57complicated things that I
08:58Abstract together and I turn them into this one really simple thing because the cat is really simple if you just say the word cat
09:04Very simple if you start looking at how it's constructed
09:08Whoa, that's really complicated, right?
09:10But we don't because we already have it it's ready and a lot of times you're even now
09:15You're working with movie clips. You're working with sprites. You're working with text fields. We've worked with the date class
09:21We've worked with math. We've worked with a lot of classes and
09:25You probably didn't stop and think well, wow, this is a really really complicated structure
09:29I wonder what's happening behind the scenes there. Why because just our human nature. We got something. It's working
09:35It's simple for our API, which is called the the I don't remember the acronym, but doesn't really matter
09:41That's our front-facing methods the things that we have access to I'm sure if we google it or some other
09:47You know geeky someone that has notes, which I don't would probably know that acronym, but doesn't really matter
09:53It doesn't matter to you when you're programming either. So what is that API that? Oh, thank you. Thanks, Danny
09:59so application programming interface, so
10:02But really what's important in that is that you have like there's something that it could it could have hundreds of methods
10:06We don't know all that we know is it has you know, two two functions
10:10One is feed me and the other one is meow or talk and and and that's all we needed
10:15So when we're going back into this really really simple construct
10:19Construction which is our our ball. This is really really simple obviously because we it's only visual
10:25Now we've worked with it before we didn't play with it too much, but movie clips are classes
10:31It's a class of a movie clip which that's why it enables us to duplicate it and move it all around the way we do
10:38Now until now we worked only with one class
10:40We worked with our main class and let me just like double click on the eraser to delete everything on my screen
