Class 30: OOP But It Actually Makes Sense

Introduction

OOP baby what's going on everybody good morning good afternoon good evening hope you all are doing well what's going on everybody welcome back welcome back we got a got a good class tonight we got a good class tonight tonight we got the oop we're gonna talk about it we're gonna spend some time making the basics make sense it's such a hard it's such a confusing it's such a weird topic when you're first starting out but i promise you i promise you we're gonna break it down in a way that makes sense with real examples. No stuffy definitions that take you a year to figure out. We're going to make it make sense. Welcome in, everybody. As always, let's give folks a few seconds to get in here. Hope you're doing well. Oh, it feels good to be back. Tuesday was a good class and good to get that review in. Get some spicy challenges in. Good to see you all. Tonight is ideally a a shorter class. We're going to cover two of the four pillars of OOP, and then we're going to do some working together time. Miriam, hey, what's going on? We'll do some working together time. So that's the goal.

The goal is to get through these like meaty topics, walk away, understanding why these things are important, and then maybe get a little bit of time in to work together on a project. Oh, thank you, everybody is already in here. We already got a lot of wild stuff happening. Hello, it's Rufio with the raid 86 folks, let's go. Thanks for hanging out with Hello, it's Rufio. We got some lovely stream team members now folks. And we got another one to announce very, very soon. So super excited. Next week we're announcing another stream team member, but it's popping off folks. I can't tell you how amazing it is to see the community, go to all the different stream team folks, right? To be able to go from learning about JavaScript to working together, to pushing that, doing all these different things and to have all these different times that we're live and coming together as a community is really, really like, that's the end goal folks, right? That's the end goal. I love it. And to see so many of you showing up for the stream team, uh, streams is it's just next level. I people grind for years to hit 86 people grind for years to hit 86.

And the fact that we have that many folks go into stream team this quick. I love it. Love to see it. Rufio is crushing it. My will is crushing it. And we got another person coming through soon. Super excited. Alrighty, folks, you know how we like to do. Today, we're going to walk through a little bit of objects review, just a little bit of review, nothing too wild, just a little bit of review, and then we're going to talk about some OOP principles, and then we're going to hopefully work in teams to build a tic-tac-toe app. All right. I was going to start off with some questions. If you've got questions, I hopefully have some answers. Why does this look smaller? There we go The question of the day is what was your favorite? What is your favorite ice cream flavor?

What is your favorite ice cream flavor a Lot of vanilla chocolate fans interesting cereal milk mint chip I'm I think I'm a I'm a chocolate chip cookie dough type person But I I've been tempted with the the mint chip back in my days. So it's a toss-up Between cookie dough and mint chip. Those are those are two competing flavors We got some chunky monkey some coffee What strawberry a lot of cookie dough a lot of mint a lot of mint lovers Dorian ice cream, that'd be wild. Okay I see all some banana thrown in there. Rum raisin. Cookies and cream, that's a classic. They have abuelita ice cream, that's wild. Okay I like seeing some of these like ice cream flavors, I didn't even know they made ice cream like that. That's pretty dope. Cool. All right, thank you. I love seeing that, that's awesome. So, always start off with some questions. If you got some questions, I got some answers. I always just like to give folks a few seconds to get in here before we get started.

Yeah, some people do say that the mint tastes like toothpaste, I feel bad for those folks. Just like the cilantro folks. Do we need to have our 100 devs project thought out, code war solutions on GitHub and professional checklist submitted? So you should have kind of put in a lot of work on the professional checklist. I won't really ask for it until next week. So next week I'm going to ask for you to submit all that stuff. You should be pushing your code wars every day. So you should be doing your code wars, saving it to a JavaScript file on your desktop, and then pushing that to GitHub. Just the every day you get the beautiful, beautiful green square that our recruiters are looking for, right? And so the idea is that you will be able to every single day have a green square because you're doing a code wars every day and pushing it. Now, I'll eventually ask to see that repo, but it's more for you to start building up that use of Git and GitHub, making it a daily practice, and then also getting those green squares. Yeah. When is client due? That is due May 5th, May 5th. Remember, it doesn't have to be done.

We just need the contract or whatever you signed. Cool. And if you're having trouble with Git and GitHub, don't worry, I know we just had the one class. Come on Sunday for office hours, and during office hours, we're gonna put in work to get done more Git and GitHub. We're gonna do lots of practice. I'm gonna do, I'll show you how I get my code wars live on GitHub. I'll walk through all the steps. We'll ask tons of questions. We'll get through it. So don't worry. If you're having trouble with the Git and GitHub, come back on Sunday for office hours, and we're gonna push through it and make sure it all makes a little bit more sense. First time working in groups, any recommendations? Oh, that's great. When we get to the end, I'll share some tips, I think, for working in groups. In the beginning, I really think, if you haven't read our Discord rules, and I know a lot of people just click it and they join, go back and read those rules.

There's some really good tips on how to be a good teammate, like fused into those rules. And I always like the see the best in each other and give folks the benefit of the doubt, right? Like try and see the best as you're working with individuals, make sure you're communicating and listening and make sure that you're just trying to understand that we're all here to learn. And for some of us, we have to learn how to work with others well. And that's part of it. That's part of doing a bootcamp journey. That's part of working in teams is because engineers rarely work by themselves. They're often on teams. And so getting better at working in a team and having your first mistakes working in a team happen here and not on the job is part of it. But always be kind, as always here in Twitch chat, on Discord, if it's not the kindest thing you can say, then don't say it, right? I think that translates really well into working with groups. So give people the benefit of doubt, be kind. And if you can keep those two things in mind, and you can work well with others in groups. But that's what we practice it. There's a reason why we do light group work and then more serious group work.

And then by the end, large portions of what you'll be responsible for at 100 devs is group work. And these groups become really important. The groups that you work with later in program and let's say like 10 plus weeks from now, those groups become really important because they will be one of the basises for your references. When you need a peer reference or someone that can speak to the quality of the code that you've written, well, guess what? You can share the folks that you've worked with in those groups. And so working, right? Working through how to work better in teams, getting to know folks, you are going to work on those things and something will get better at over time. But in the end, it's gonna be a really important thing to be able to like look back and be like, Oh, here's somebody that knows what I've worked on, has helped me with code, and boom. Is this webcam or voice only? It's up to you. We're gonna use Remo, which can be webcam and mic. But for some folks, Remo, they can just never really get it to work. It's kind of buggy. We always have our Discord voice channels, which you can use as well. We don't have to worry about that for right now.

We got a whole lecture, one of my favorite things to cover before we get even close to working in Teams. Yeah. Yeah, this will be after stream Cool Text is an option. Yes, it can be All righty Let's go ahead and start pushing through If you haven't checked in, please go ahead and check in exclamation point check in and gives us a link to a tweet. Go ahead and like and retweet that tweet, please. And it just helps us to spread the good word. Folks can find us not to pay so much money for a bootcamp. And then also it's attendance. So as we get closer to the end, as we get closer to the hunt and we get into the meat of the support that you're going to need, we check attendance. So make sure you've checked in so that way we know that you were here. All right, this topic above all topics can be something that really, um, really kind of get you in your feels a little bit that can get you into the trough of sorrow a little bit. And so my promise as we go through, uh, these very important topics is that I'm always going to explain the why. I feel like I've gone through a lot of books, a lot of materials, a lot of things where I got to the end and I'm like great. I kind of understand it. I kind of know what's going on, but I don't know why.

And it was always one of my major frustrations when I was learning how to code or whenever I'm learning something new is, yes, I can see it. You've given me good examples. We've played with it. We've built with it. But why? Why? Like, what was the reason I needed to learn this or know this? And when it comes to encapsulation, abstraction, inheritance, polymorphism, we got to understand the why just as much as the how and what and the build with it. And so, yes, these topics can be difficult. This will not will not only be our only time seeing these topics. We're going to get the repetition and we're going to get different examples. I'm going to show you from different places, different viewpoints, how to get through this important, very important topics that, in my opinion. There's really just no good material that gives you how the what, But more importantly the why like why will my life as an engineer change when I use these things? And so that's what we're gonna get to tonight folks All right, remember no networking until May but May is coming up soon folks. May is coming up soon Hmm I'm still alive I think I think my computer just crashed.

Hold on. So I am live, but I think my laptop just died for some reason. I don't know why. Yep. All right, that died. I don't know why that, that zonked out. All right. We're going to go to, uh, I'm going to go to main shot real quick. All right. I think we are all set. I don't know what happened, honestly, but that's all right. You got got, you got got, exactly. Now you can see how long it takes me to get everything set up before I go live. All right, we're back folks. I had to put the hair up.

I was like, come on now, I gotta do this quick. All right, here we go, we're back. All right, so no networking until May client deadline is March 5th, right? March 5th client alternatives. Remember if you can't get a paid client, for some reason, you can volunteer for a grassroots organization and you can contribute to free and open source software. Good place to start is first timers only. Oh, should I say, should I say March in there? It's May, May 5th, not March 5th, May 5th. May 5th, not March. Grassroots volunteer and free and open source software are all viable. Alright. Thank you for bearing with me. It looks like everything's good. We're back online. Remember, tomorrow, Friday, we are doing a live crafting your story.

And so that'll be live on and discord discord at 6 30 p.m. Right 6 30 p.m. Will be live on discord. We do the group projects. We're catching up Yes, so we're live tomorrow on discord. We're gonna bring up I have no idea whoever wants to come up is gonna come up and I'm gonna craft their story live They're gonna tell me about their background and we're gonna figure out how to build that background into a good story That we can sell to recruiters hiring partner hiring partners engineering managers, etc. Will it be recorded? No, this first one won't be recorded. I will do more of them in the future, but this first one won't be Yeah There's there's a few perks to being live folks. I know it's tough There's a few perks to being live, but we're gonna do it again. We'll do other ones this first one won't All right Office hours this Sunday, we're back with our full office hours. So this Sunday is going to be like a full, at least three hours. We're going through Git. We're going through GitHub. We're going through, um, we're, we're going through some of the stuff that we'll cover tonight.

Anything that we need to review, we'll still always answer questions like we normally do on Slido. Uh, so office hours, Sunday, so Friday, 6 30 PM tomorrow for for crafting your story and then office hours on Sundays. Cool. Chat, what are objects? What are objects? Everything. Everything. Make sure my slides are working, sorry. All right, looks like we're good. Cool, what are objects? Everything, exactly. They're collections of variables and functions, right? They're collections of variables and functions. Now, these variables and functions, we call them properties and methods, and they combine, and we've been using them, right? We've been using them, but do we fully understand why we've been using them, right?

We could just use functions. We could just use variables. Why did we have to use them? And so this is a method of learning that I implement in my own life, but it's something I also implement in my teaching. And it's also something that I think is a really good practice for y'all. So right now I see learning as kind of like three phases, right? Using understanding and then building once you have those two combined. And so at first we're kind of just like using these pieces. we're using objects, we're creating properties, we're creating methods, we're using constructors, we're doing these things that we kind of really, we understand like the use of them, right? But then understanding why we use them is another level. And one of the things that I find that a lot of folks get tripped up on, especially at this phase of learning, is they try to understand. They read eloquent JavaScript and they'll just bang their head against the keyboard because they're trying to understand every little bit. When if they had just started to play with it before trying to understand, copying the code, trying to break the code, moving the code around a little bit, right? That would help them unlock the understanding bit. And then once the understanding bit starts to come into focus, it doesn't have to be all the way there.

Some folks really put pressure on themselves to fully understand everything before they start building. And that's also something that can slow you down significantly. So use it, play with it, break it, then try to understand the bits that you're playing with and then try and build something with those bits. And so you're going to see this pattern happen over and over again here at 100Devs. I'm going to introduce stuff to you. We're going to use it. We're going to understand the syntax, we're going to play with it, but we might not understand why. And then we cover the understanding. Then we build with it. So tonight we've been using objects. We're going to get our repetition on the objects that we've been using. Then we're going to add this layer of understanding. Like what do objects bring to the table? What is this OOP thing? What does that bring to the table?

That's going to help my day-to-day life as an engineer. And then how can I use these things, these best practices, these paradigms to build stuff that's real, that can go into production, that I would feel comfortable showing my future teammates, that will be something that will be stuck in my portfolio, something that will be what I am proud to show off during interviews, right? So use, understand, build. I think this is something that can help alleviate a lot of anxiety and stress that comes along with learning to code and give yourself that grace that freedom to just use and play with stuff before you understand it and then once you've been using and playing it then try and understand a little bit but don't have to go full bore right you don't have to go all the way complete understanding try building with it and then that building will unlock the last bit of understanding right and so that's something we're going to see over and over and over again. I kind of like to be on the nose with it when we're talking about such meaty topics tonight. What we're going to use, we're going to understand, and then we're going to build. All right. Now tonight, we're going to make some nerds real angry. They can't help themselves. The code we need has always come out in full force on this class and any of the OOP classes. Here's something that I need you to know. Your theory doesn't make sense. Like, yes, you know the in and outs of computer science theory, but when you try to explain that theory to someone that's just learned the basics of objects, it makes no sense. In your attempt to educate on theory, you have lost sight of actual understanding, actual applicability to the code that folks are writing. And I have to tell you, I've read the books.

Yes, I've read the books. I've read the meaty ones. This is my Thursday copy. You don't want to see my Wednesday or Tuesday copy. This is my Thursday copy. I've read the silly books. I've gotten through them. This is my Thursday copy. You don't want to see my Friday or Saturday copy, right? I've read the books. I've learned the theory. It has no place in the first class. It has no place in the first class. I want you to walk away understanding why encapsulation is important. Why abstraction is important, what it's going to bring to the table, what it's going to help you with.

I don't care about the, well, actually encapsulation in this part theory is follow up. No, go fuck yourself, right? We're here to learn. We're here to understand. We can save those dusty three page explanations for two to three weeks from now. We don't need those right now, right? Save that. And I know, I know for some of you that are here, the code weenies that are here, I understand that this is gonna be very difficult for you. So what I have done is on any page that includes a definition that attempts to explain and lead someone to understanding instead of giving the textbook definition, I've put a little, a little asterisk for you. So when you see that asterisk come up, you can take your headphones out, right? You can close your eyes and you can come back next week, right? That way we're not going to make you shake vang angrily. Right? So when you see the little asterisk come up, that's your cue. Close your eyes, take your headphones out and you're good.

right all right now I think it's really important to spend time on the conversation we can get to the academic definitions later on well the other thing too is that I'm throwing around a lot of big words I'm throwing around encapsulation abstraction inheritance polymorphism when I first heard these words. They're big words. I didn't understand them, so I treated them as disrespect. And so when we're looking at these definitions and you're throwing around these big words that I understand, you got to understand that makes me feel a certain type of way and I'm going to treat it as disrespect. So we're going to try and get rid of these big words. We're going to try and talk about these things in a language that actually makes sense to the humans that just learn JavaScript and we're gonna save the big words and the disrespect for a few weeks from now. All right. We both rep the same smart tech. If you know, you know. Now you're both gonna get clapped up. All right. Chat, we talked about objects being a collection of variables and functions. we are going to just do a little bit of review and then we're gonna jump into how we can start using these objects and start talking about those pillars of object-oriented programming. So we've put the nerds on standby. We know that we're gonna take some creative liberties tonight and if you need to take some time, that's okay.

All right, so we talked about objects, It's a collection of variables and functions. They represent the attributes and behavior of something in our program. We call these variables properties when they're tied to an object, and we call these functions methods when they are tied to an object. We like to think of like a physical object when we're trying to think through this to tie it to something a little bit more real. I like to think of a stopwatch. A stopwatch has properties like color, shape, size, even things like the minute and seconds, but it also has methods that are tied to it. Behavior, start, stop, split, reset. These things that we've been building up over the last few classes. We see here that we're creating a stopwatch using what type of notation here? What type of notation we're using to create an object here? Yeah, we're using literal notation here. We're adding properties and methods here using what notation? Dot notation. What are some other ways that we could create objects though? If we didn't want to use literal notation, we didn't want to use this dot notation.

What if we wanted to make a lot of objects? What could we do? We could build constructors, exactly. And then if we wanted to put a little bit of syntactical sugar on top of our constructors, what could we use? Yeah, we could use our classes, exactly. So we talked about the ability to create lots of objects, just like a factory can create lots of objects. Well, we have our constructors, which can help us spit out a lot of objects. And we had this original syntax. And then with the newer versions of JavaScript, we put some syntactical sugar on them and we got our classes. So what I would love for us to do is to very quickly work through building out a class just to get this stuff in our brain, just to get that review in. And then once we work through this objects practice, we will move into OOP or object oriented programming. Cool. So let's go ahead. If you haven't downloaded the materials yet, go ahead please. They're always on Discord in the follow along materials channel.

This is class 30 materials. Can you believe after this class we'll be halfway through folks? We'll just take a second for that. Hold on. We just take a second before we start working on this. After tonight, we're halfway through folks. Could you imagine in the beginning when you first saw that Reddit post that in just a few weeks you'll be sitting there going, oh yeah, Leon, when we create an object it's a collection of variables and functions. We can use literal notation and dot notation to build the object. But now we're looking at constructors and well the constructors got some syntactical sugar and now they're and now and now we got classes What a bunch of nerds What a bunch of nerds. I love it. Y'all a bunch of nerds and I love it Right, like could you imagine could you imagine just a few weeks ago knowing that you would be able to have that full conversation? Like like that that it makes sense Like that those words have meaning to you and that you keep showing up and tonight we're going into things like encapsulation and abstraction and we're talking about paradigms of coding like what? Come on now that's huge and after tonight we're almost halfway through so you know next week's got to be big we know next week's got to be big because that next week we're officially halfway through and so next week's got to be big this we got to celebrate but come on now if you're not proud of yourself i know i've been saying this a lot recently but if you're not proud of yourself you're messing up because it not everyone can do this right and so i'm just i just want to make sure that if nobody tells you i'm hella proud of you like really proud of you for showing up committing to this process digging deep when things don't make sense a lot of folks want to to do this, but they don't. You're all built different. All are built different.

All right. Let's go ahead and take a look at this code. We have in the starter code for today, this objects Espresso machine. So let's go ahead and open up this JS file. I have the index.html file, just so we can open it as well. And I want you to create an Espresso machine. Actually, I don't want to make a constructor. I want you to make a class, sorry. This should say class. I want you to create an expression machine class that makes expression machines with four properties and three methods, four properties, three methods, okay? So let's go ahead, we've done this before. We've been down this block a few times. So let's go ahead and put four minutes on the clock. Four minutes on the clock for this one. I know we can get through this one.

We've done this quite a few times. Use the class-based syntax, please. is class-based syntax, four minutes on the clock, you got this. But dude we've talked about them in class they're in the slides too if you need to take a look at the slides Here's the slide if you need it The first book I showed was The Structure and Interpretation of Computer Programs. It is the meatiest book I have probably ever worked through Glad to hear it, Jacob. Tony Stark, I haven't seen it yet, but I'll take a peek through after after class. Jam, just put them here in chat. I don't even want to say the name of the book again. Please do not read this book. This book is like not helpful unless you really want to nerd out. And that's like, that's once you have a job book, like once you have a job, you can go back to that book. We're going to talk a little bit about that today, actually. Nene, we are just making a class that has four properties and three methods. I'm leaving this slide so people can take a peek at the class syntax. Misinformed cars.

Hey, congrats. Happy birthday. Happy birthday. First time in a while I can say done, hey congrats. If you're having to look at this because you don't remember, that means to me that you might need to spend a little bit more time with Anki and this definitely needs to be one of the things in your Anki deck. Radio, welcome. Make sure you join. You can do exclamation point 100 devs here in chat to learn everything. But if you join our Discord, we agree to the rules and there's this lovely catch up channel. You can definitely work through all the material with the catch up crew. Spillbatch that I have a hard time making Anki slides that mean anything. That's how it starts. And then eventually you find what works and doesn't work. You just kind of got to get into it. I've created a lot of crap cards in my day, but they just get deleted or I remember them and I don't ever think about them again.

All right, folks, come on back. Let's take a look at this. Do you like rock music? Not really rock, but like ska, Five Iron Frenzy is my favorite band. Alright folks, come on back, come on back. Also listen to a lot of punk. Really into idols right now. Yeah. Never fight a man with a perm. As I just play that song on repeat right now. Cool. All righty folks, let's take a look at this together. Pretty sure I would have hung out with Leon in high school. That's like a nice compliment. All righty.

Let's go ahead and build out this class. So we're going to build out our class. Remember the class structure is a little bit different. So we're gonna call this EspressoMachine, whoop. And I like to keep my classes with a capital letter anyway. Espresso, there we go, EspressoMachine. All right, now instead of our EspressoMachine, we need our what first? We need our what first? So we have our constructor first and then we're going to have our methods that come after our constructor. So what are some properties that our Espresso machine should have? Zenkits, hey, thank you for the hydration, I appreciate it, cheers to you. NekoCatz, hey, thank you for the tier three, that's wild. I see some models, I see brand, I see color, size, I see price. I kinda like those. Let's do color, make model price.

So this.color equals color. Uh, this dot make equals make, uh, this dot brand or model. I should say model equals model and this dot price equals price. What am I missing? Has grinder. Nah, my expressive machines never have grinders. There's really no good prosumer espresso machine with a built-in grinder, in my opinion. Yeah, I'm missing my parameters. I need to put the color, the make, the model in here, right? Color, make, model, and I need price in here, too. Beautiful. All right, so we got our constructor, color, make, model. Remember, we always have to keep in mind, Let me connect my iPad again. Sorry, I realized that my iPad wasn't connected after the restart. And I probably need to start Demo Pro too.

All right, here we go. All right, there we go. So the thing we always have to keep in mind, right? The thing we always have to keep in mind is that these right here are what? These right here are what? What are the things I just circled? They're properties, exactly. These are the properties. However, these over here are the what? Exactly, I see some folks coming with it. The parameters, right? The parameters. And so what you have to realize is that the parameters are coming in up here and correlating to these parameters over here. These are just the properties that are gonna be tied to the object that gets spit out of this constructor, that gets spit out of this class. Often, they are the same name, but they don't have to be.

I could have called this zabumafoo and then had zabumafoo here, and I still would have had a property of color that then had the value that got passed in. So the beautiful thing here is that we have our properties laid out, our properties and our methods. There's one other thing that's wrong here. What else is wrong here? There's something that's messed up. Yeah, it's the parentheses, nice. Why don't I need parentheses here? Why don't I need parentheses there? It's not a what? It's not a constructor function. It's not actually a function there. So since it's not a function, we don't need those parentheses. And so I think a lot of folks, when they're switching from the constructor to the class syntax, they always leave it because they're so used to it being a constructor function, but it's different. It's a little bit of syntactical sugar. It's a little bit different.

The constructor function is here now. Cool. All right. We need some methods. What are some things that our espresso machines should be able to do? What are what are some things we need here? We need to turn on we need it to froth milk we need it to brew we need to pull a shot we need to heat Turn on turn off All right, I like turn on we can do turn on brew and Or we can make like we can turn on steam and like brew, right? So let's go and do that. Let's go ahead and turn on Cool then we can have steam And then we can have brew Cool. Now we have the ability to to turn on to steam and to brew Let's just put some console logs in here I'm just going to say today I am now on cool steam. We're going to say it's summer sale 50% off. All right, there we go. That's steam the percent off and then brew. We're going to just have it console log. Good stuff coming your way.

All right, there we go. So we have an express machine that has a constructor that helps us make four properties on the objects. And then we have three lovely methods, turn on, steam and brew. Let's go ahead and actually create a, an object here. And so let's go ahead and, I'm gonna see if I can keep this on screen here. Let's go ahead and create an object here. So anybody have a favorite espresso machine? I'm not shilling for steam. Revel, Espresso, Moka pot, okay. Okay, gaja, that's my favorite. We're gonna go with the gaja. There we go. Let gaja equal, and we're gonna do a new keyword, espresso machine, and we got the pass in our values now. So we're going to pass in the color, the make, the model, and the price. I'm thinking the gaja classic pro.

Now the gaja classic pro is a beautiful espresso machine. They came out with this like beautiful red color recent well not recently, but beautiful red color the make is gaja the model is the classic pro and This is like this is like the best entry-level prosumer Espresso machine right like getting everything, like getting good espresso under $800 is not an easy feat. And so when you throw in the espresso machine, the grinder, all that funny stuff, you wind up realizing that for dollar for dollar, the Gaggia Classic Pro is probably one of the best espresso machines on the market, barring getting something like refurbished and using that or making some modifications to another one. All right. Now, what do we think the price for a a gaja classic pro might be? There's a y'all pretty close you can you can typically get one in the range for like four to six hundred dollars If you like go on certain websites, they'll try and sell it to you for 800, but yeah, like around four to 600. If you know where to look, you can get it for 400. So we'll say 400 for the price. Cool. All right, so now we have our lovely object. Let's go ahead and save it. Let's see if we can open this in the browser and make sure that it's actually running. Open in browser. All right, I forgot that it was still the bring it on one. Let's go take a look at the console.

Let's ask for our gacha back. We got it. Here we go. We got the lovely espresso machine. It has a color red, a make of gacha. It has the model of classic pro. It has the price of 400 and it should have some methods too. So let's go ahead and try using one of the methods. And I think we had turn on was one of ours. There we go, good day, I am now on, beautiful. So it looks like we got not only all of our properties, let's see if we can get one of the properties back, let's get the price. Cool, looks like we got the price, we got the methods, we're doing good. Alrighty. We're feeling good, we got this review in. Public private, hang around, we're going to talk a little bit about public private later on today.

All right, first try, what type of tea? This is a Tazo Vanilla Caramel Chai, I think that's my go to recently. Alrighty, did this in the JS Cardio, nice. The JS Cardio, definitely if you haven't done that yet, do it as part of the work that was assigned. Really good practice for all this stuff. All right, so we got a review in, we're using the lovely class-based syntax. We built our Espresso machine and we've been using these objects. And there was a reason why I had you watch that video. If you noticed in the announcement for today's class was to watch this video of Cardi B because whenever I'm learning to code, I feel Cardi inside me. I feel them just like bubbling out because I'll read one of these whole dusty... This is a fun one. I'm not hating on this book. This is like a fun one. I'll read this whole book and I'd be like, all right, great objects. Yeah.

I know how to use them. I can, I can play around them. But what was the reason? Like, why, why should I use objects? Why do I need factories? Why do I need classes? Why do I need constructors? What is the reason that I needed all this stuff? Right. And I constantly am learning things. and the whole time, every part of my being is screaming, why? Is screaming why, right? And so tonight, I'm hoping to answer a little bit of reason as to why we use objects, why we need these things called encapsulation and abstraction and why we need these factories and all this stuff. And I hope that after tonight's class, So we walk away with understanding why that we that we understand, right? The why behind what we're doing.

And so if we can walk away tonight, understanding the why. I'm going to feel really good. So before we do that. Before we before we before we before we jump into the next little bit of what we're going to cover this evening. I want to take a break. Let's go ahead and take a break. We're almost at the top of the hour. If you're new around here, we like to take breaks at the top of the hour to be healthy, to give our hands and eyes a little bit of a break. I'm gonna put five minutes on the timer here. Please, if you're able, get up, move around, hydrate. All right, look out your window longingly at the light post so that your eyes focus on something farther away. And we'll be back in five minutes. I'm gonna leave it up here. All right, I'm going to run some ads so you actually have to take a break, too, so that new folks can come and not have to sit through them. All right, folks, see you in five minutes.

When we come back, we learn why. the You You You You Never does, DiffKrush, never does. Is there a start over crew? That's actually not a bad idea, but definitely join the ketchup crew. We have so many folks joining the ketchup crew every day. So you can definitely create like threads too to stay with folks. Will there be another super review? Yeah, we'll definitely get another super review. And once we get all the way through objects, async, wait and promises next week, we'll do a review with everything. Basically we'll go deep with JavaScript, so we won't do like HTML or CSS, but we'll go Review everything in JavaScript before we get into the back end Can you do freelance work as partners absolutely, but you both need your own contracts Because you you want to be the beautiful thing about having your own free like you can do it, but If you do it by yourself It's a little bit better because when a hiring partner or someone asks you like show me what you've built There's no ambiguity around it. Like I built this whole thing for this client. They paid me money Faze Clan Intern, hey, thank you for the gifted subs, Faze up, let's go, get me on the Faze Clan, they need their first teacher, their first educator, Faze Leon, there you go, don't Let the 100 does fool you. All right, folks. Come on back. Come on back.

Let's get into this. Let's get into this. I just watched this all second video. I feel her. Yeah. I, that's why I wanted you to watch it. Like I, I really do. Like when I tell you some stuff, like, of course, sometimes I'm like joking, but no, when I read these books the whole time, the whole time I am thinking through, Like why, what is the reason? I wish they would just start by saying, here's why you need this stuff and then go into all the nitty gritty details. But none of these books do it. They're all like, it's almost like they can't remember being beginners, right? Almost like they can't remember being beginners. Which is why I love, it's why I love with every fiber of my being the stream team. there's nothing I can do to go back and remember everything that it was like to be in that in that moment in time but with the stream team we can we could have folks that are in the thick of it in the mud with you that are explaining things and seeing things and with those eyes I try really hard but the stream team makes it so that there's someone with your same perspective and you can and go through it together. All right.

Told you folks, they're not gonna be able to help themselves tonight. They're not. All righty. Let's chill the music here. All righty. So, As our code base gets larger and more folks join the team, can we keep our code organized? It's a big question we have to start asking ourselves. We're going to start doing more teamwork. By the end of program, we're going to be building large scale applications with each other as part of the agency, right? We're gonna be building these bigger projects together. And right now, as our code bases get larger and more folks join the team, can we keep our code organized? It's a question we need to keep in our brains. Another question we need to think through, is it easy to add new features and functionality? The way that our code is organized now, is it easy to add new features and functionality? Can we make it so that new folks can join easily?

Can we keep it organized? Can another developer look at your code and actually understand what is happening? And I'm seeing a lot of yeses, but I feel like it might be a no. And I'm gonna show you why in a second. So the things that we gotta start thinking about, It's like we've been writing code, right? And the first rule of writing code, the first rule of writing code at 100 devs is what? What is the first rule? Above everything I'm about to talk about, above everything I'm about to talk about, what is the first rule? Be a baddie, exactly. Be a baddie, write bad code, make it work. Make it work, right? Make it work. That is the number one rule at 100 devs. be a baddie, write bad code, make it work, right? Everything else is extra, but our end goal is to be able to work with others.

Our end goal is to be able to build bigger and bigger things. And our procedural spaghetti code might start to hold us back a little bit. So something I need you to think about tonight, and I'm gonna show you some examples, but I want you to think through these questions. As our code base gets larger, the way that you're writing code right now, can more folks join you? Will your code stay organized as they join? Is it easy for you to add new features and functionality? Can another developer look at your code and understand what exactly is happening just by like looking and reading through it? And can you make changes without losing sleep at night? Like if you and another developer are working on the same project, can you both make changes and not be afraid that it breaks something else? And so I think, and we're gonna see some examples, that's a no right now. And that's okay, because the first rule is be a baddie, write bad code, make it work. But what if there was a system? Nay. A paradigm. Nay.

A set of rules or an agreed upon structure to our code that we could follow that would make it easier for us to add new things, that would make it easier for us to read through what we had already written and see the code that's already there. And what if we could structure our code in a way, what up, Law, we could structure our code in a way where we weren't afraid to make changes, where we could push code at five o'clock and go home and not sweat the entire ride back, you know? What if there was a system, a paradigm, a set of rules? Notice the warning on the slide, right? Notice the warning on the slide. Whenever you see this warning, you know the next slide's about to get loud, about to get flashy. I'll have these on all the slides before we hit it. So what if there was a system, a paradigm, a set of rules that made it easy for us to add new stuff, that made it easier to read what we already written, that made it so we weren't afraid to make changes? well I did it. My cat jumped off the chair and ran. All right. So that's the whole point of object oriented programming is that we're going to start being able to answer these questions with a system that enables us to work around them. All right. I forgot that we got to go to the next slide hold on and second All right, let's see some code. Let's see some code.

We talked about it, but let's see some code, you know what I'm saying? Now the juice is going. Let's see some code. All right. So let's take a look at this code here. So I want to build some code to start helping us as we start thinking about the agency. And so I wanna be able to calculate my profit when I work with a client, right? I wanna build something so that I can calculate the profit of when I work with a client to get work done, right? And so I'm standing on my keyboard. So here I have, uh, some variables, hourly rate, hours, tax rate. Uh, once again, this is a reminder, I'm not a tax professional. None of this is tax advice. Please don't think this tax rate is your tax rate. Getting that out there, pay your taxes. All right.

So we have our variables here for hourly rate, hours, tax rate. We have a function here that we can use to calculate profit. And we can see that I here am creating a variable called profit. I am calculating my profit. I am passing in the hourly rate, the hours and the tax rate. The hourly rate falls into rate. The hours falls into number of hours. The tax rate falls into taxes. You can see we have a simple formula here We're calculating the rate times the number of hours times the rate of taxes, right? And this works, this works. And this look, this might be some code that we would really write, right? This looks like something that we would feel comfortable writing to calculate the profit that we make when working with a client. Now the question I have, is it easy to add new features or functionality with the way the code is written now? Let's take a look. Here I added just one other bit of functionality.

I just added one other bit of functionality, which is like how much do we need to hold on to for taxes. So let's see if we can follow this through, right? We have our hourly rate, our hours, our tax rate. We have the ability to calculate our profit. We have the ability to calculate our taxes held. And so for this to work, we need to calculate our profit first. And then once we have our profit, we can calculate our held for taxes, right? And so here we're passing in the hourly rate of 250. Oh, Shit, now my clients know my hourly rate. My number of hours and my tax rate, those get passed in, right? Those get passed in. And then I calculate my profit. That gets spit back out. It's stored in profit. Then I'm able to use profit as a parameter that gets passed in.

I can then use the profit to calculate how much I need to hold for taxes, and I have that spit out. Now all of this works. This is all some very procedural code that we're used to probably writing. Now the problem is, can another developer look at my code and understand what is happening? Let's take a look. Can you as another developer figure out what's happening here? What are some problems that you might run into when you're looking at this code? What are some things that you're thinking about when you're looking at this code? Sure, but there's too much to analyze. Exactly. There's too much to analyze. Our parameter names are all over the place. our variable names are all over the place, right? And just adding one line of functionality kind of made this harder to understand, right? Can we agree that just adding this one line, it's that we're not breaking the bank right here.

We're not breaking the bank right here, but just adding that one line, right? Just adding that one line is already probably causing us a lot of problems. And we want to build out a full application that we can use to help manage our agency. So could you imagine adding 50 to 100 other things that we need to keep track of in this procedural manner? Sheesh, I don't know, I don't know. And, and, and could you make changes and sleep at night? Like, could you, could you make a change to this? Could you make a change to this and feel comfortable pushing your code? Like if we're, if we're working on a team, could you change any of this? Could you, would you feel comfortable changing hourly rate? Would you feel comfortable changing taxes? No way. No way. And imagine this is just what, this is what, this is what two bits of functionality to, to, this is two bits of functionality. And we're already like, Leon, I don't know.

I don't know. I, I can't do this. Right. I can't do this. Right. And it's with two bits of functionality. And so if we're building out full applications, the way that we've been writing code just won't work. It makes sense. It makes sense. This works. It makes sense. We could sit here. We could get up into it. Okay, this, this. We could go full Steve Madden, right?

We can go full Steve Madden. We can bring out the nuns, right? We could we could figure it out We could figure it out Right, we could figure it out but What if there was something we could do What if there was something that we could do? That would make it so we could get rid of all this mess This is just mess to me. It works. We can read it. It's procedure. We can go from top to bottom. We can understand it. But what if there was a way that we could make it so that we could solve those questions easier to work with others, make changes without losing sleep at night? And one of the first things we realize is that if we look at this code and we really think about it, there's two things, right? There's two things that I'm noticing about this code. there's data, like our hourly rate, our hours worked, our tax rate, and then there was functionality, like calculating the profit and the taxes held, right? So when I look at this code, I'm really seeing those two things. I'm seeing data and I am seeing functionality.

And so what if there was a way that we could fuse this data and functionality together, right? We could pull it out, right, we could pull it out. You could pull it out, right, we could pull it out. If you know, you know, right? We could pull it out. What if we could fuse our data and functionality together so that it makes a little bit more sense? Right? That makes a little bit more sense, It's a little bit easier to keep track of what's going on. So here is my serious business person object. Here's my serious business person object. Let's take a look at this, right here. We have our hourly rate. We have our hours worked. We have our tax rate, and then we have our calculate profit. And we have our calculate profit.

Now look at calculate profit. What's CalculateProfit doing that was different than that messy code we were looking at not too long ago? One, it's a lot easier to read. I agree with that. The parameters aren't all over the place, right? The parameters are all over the place. We are using the hourly rate, hours, and tax rate that are tied to the object. And we're not using a class right now because it's just too much to fit on one page, right? But we would build a class with a constructor that would do this, right? But for now, just so we can get the idea. Now, we don't have this mess that's everywhere, right? It's a method now. It's way more readable. We can see the hourly rate, the hours, the tax rate, and it's not changing throughout our code. We can go and see, all right, I wanna calculate the profit.

I can go and see where calculate profit is made. And I can see that it's, oh, it's referencing this hourly rate, this hours, this tax rate. I know what those things are, right? I know what those things are. I can look, oh, this.hourly rate, this.hours, this.tax rate. When I see this, I know exactly where to go, right? Like, I don't have to go anywhere else inside of my code. Right? I don't have to go anywhere else inside of my code. When I see this, I know it's referring to the property on that object. Right? And it was referring to the property on that object. So if another teammate, right? If we're working on code together and another teammate adds some property up here called hours, right? They come up here and they create an hours up here.

Do I lose any sleep? No, because I'm not worried about, am I gonna accidentally use that as a parameter? Am I gonna accidentally use it as a variable? This hours up here means nothing to me because I can see that this hours is tied to the object. It's this.hours, right? So now I have my data and my functionality fused together and it makes the code way more readable. It makes it so that when I want to add new features or functionality, right? When I want to add new features or functionality, it's not wild, right? I added the calculate taxes held And now I'm still using the hourly rate. I'm still using the hours. I'm still using the this.calculate profit. When I say this.calculate profit, am I talking about some other function 400 lines down called calculate profit? No. Right? I know that this.calculate profit, because I see that this keyword is talking about this method right here.

Right? It's talking about that specific method. So it's my, my, my, my data and my functionality is fused together. It makes it way easier. I can now add more bits of functionality and it's readable. I'm not chasing stuff down throughout my entire, my entire folder structure. It makes it so that I can also do something really, really important. I can understand what the heck is going on in my code, right? I can understand what's going on. I can see that this is an hourly rate. This is hours. I can see that this is calculating profit. I can quickly read this and understand what's happening. But the other thing is I can make changes now without losing sleep. I can change my tax rate.

And do I worry that anything else is broken? Do I have to worry about some other function and somewhere else breaking? Do I have to worry about that big mess of chains that we had before? No, we know that everything is using the actual properties. So we know that this dot tax rate is looking right at this line. And we know all the other methods that we built, right? All the other methods that we built, they're all using the same data. So now we can add new bits of functionality. We can make changes and not lose sleep at night because we're all kind of agreeing to this system, this paradigm, right? And so when we fuse our data and functionality into one object, When we fuse this data and functionality into one object, you have your warning. So The nerds are in shambles. That's encapsulation. Right? I keep forgetting the other slide. We got to have that I keep forgetting while it's up to do the other slide all right, so Here's the here's here's my definition of encapsulation and I as you'll notice I've put my warning here if you're if you're code weenie when you see this asterisk This is your turn to close your eyes and take your headphones out I'm just gonna give you a warning take close your eyes take your headphones out if if Definitions that are meant to help people understand if that's going to make you shake violently.

You can't help yourself I already see you typing it There's somebody right now that has like a full paragraph typed out about how this isn't absolutely 100% encapsulation, right? You can just delete it. It's okay. Come back in a few minutes. We'll be past this. Okay. All right So to me Encapsulation and what helped me kind of understand is this just the process of storing our functions or methods? with their associated data, aka our properties into one thing. The fusing of that data, the fusing of that functionality into one thing. That's encapsulation. The process of storing our functions with their associated data into one thing. Cool. So. So, the thing we always have to come back to, the thing that we always have to come back to is the why, right, is the why. What does encapsulation help us do?

Why do people say encapsulation is important? It's one of the four pillars of object-oriented programming. This paradigm that makes us writing code together little bit more easier. Why is this encapsulation important? What does it help us do? What is the reason? What is the reason? What is the reason? I love that people haven't watched the GIF and they just have no idea. They think I'm just getting real hype off of this. Yeah, a little bit more specific though. It does help with organization, right? But it makes it so that we can do a couple things. One, we can make our code more readable. Two, and make sure that we can make changes and not lose sleep.

And it gets rid of this mess of spaghetti code because our data and our functionality is fused into one thing. Cool. Now, I have a new question. We talked about this, we talked very briefly about this idea. Is it easier to add new features and functionality? If we're using encapsulation, that's one step towards making it easier to add functions and features and functionality. But there are some other things that we can do that continue down this pathway of making it easier to add new features and functionality. So I'm going to ask for a little bit of creative freedom, A little bit of liberty when we describe this next thing, as I have done before, but I'm hoping that this little bit of encapsulation starts to make sense because I can't tell you how many books I read, how many YouTube videos I watched. I'm like, why, why would I use encapsulation? Why does using objects help? So I hope that that example helped. If it didn't, don't worry, we're going to see this two, three more times over the next few classes with more examples. come to office hours, ask your questions. But I want to lean into this idea, is it easy to add new features and functionality? So to do that, let's talk about something.

Let's talk about our Espresso machine. Earlier today, we talked about the Gaggia Classic Pro. Here it is in all of its glory. Now the Gaggia Classic Pro really is hands down the best prosumer entry-level Espresso machine. It's expensive, yes, but anything less is not gonna cut it. Right? If you want good espresso with good pours, consistently good pours, the Gaggia Classic Pro builds up a really good steam. It really presses that steam to the portafilter. You get really good espresso. And the Gaggia Classic Pro is really good at it. It was really good. Not a sponsored stream. because I'm about to wreck them. I'm about to wreck them. The Gaja Classic Pro was hands down one of the best espresso machines for that category, but it was missing something.

It was missing this lovely steam wand, right? It was missing this lovely steam wand. And so they added a steam wand to the gaja classic pro But it sucks It's horrible. It is hot Garbage, so if you're not if you're not in the know You use the steam wand to add Texture to your milk, right you add texture to your milk give you that elasticity So that you can do cool stuff with it. You can make your lattes is you can do what you wanna do, right? And the steam wand that they added to the Gaggia Classic Pro, not good. All right. Now, something interesting is that the Gaggia Classic Pro is really good at one thing, right? It really does make really good boiled water, right? The Gaggia Classic Pro is really good at heating water. The water it heats for the espresso make some of the best espresso you can make in the entry-level market. However, that same boiled water that you would use to steam your milk through that wand, well, it sucks. Right? The Gaggia Classic Pro is an espresso machine. At its core, it boils water, and then it takes that hot water, it puts it through a portafilter, and that's how you get your espresso.

And it sends some of that water, or that steam to the steam wand, and that's how you can froth your milk. But the wand sucks. So, if we are all astute engineers that we are, what should the engineers at Gaggia do? What should they do to this lovely espresso machine? Quit. They should update the wand, please. Gosh, if you're listening, please listen to us. Here are our plea. Get rid of the crappy two-hole filter. Give us a single hole that gives us more control, please. Just fix it. All right. So the engineers could probably just make a better wand, right? They can make a better steam wand. Should they get rid of the boiler?

Right, we want this better espresso machine. Everything is perfect except for the steam wand. Should they get rid of the water boiler? No. Should they get rid of the buttons on the front? No. Should they redesign the portafilter? No. They probably shouldn't. They should probably, right? probably just fix the wand. And so if they're going to fix the wand, do the engineers at Gaggia even need to think about the water boiler? Do they even need to think about the buttons that are on the front of the machine? Or can they just focus on something, right? The engineers can just focus on the wand, right?

They don't need to think about the water boiler. They don't need to think about the buttons on the front. They can just focus on the wand so we can say in this instance that the water boiling. Is abstracted. Oh boy. Oh boy. The engineers at gaja, right? They need to fix the steam one fix the wand. Please fix the wand. it's almost perfect, just fix the wand. And when they're fixing the wand, they don't have to worry about the water boiler. The water boiler is perfect. It makes some of the best espresso in the entry-level market. And when the engineers show up for work, they don't need to worry about the water boiler. They can just focus on the wand.

So in this instance, the water boiling is abstracted. Got it. All right, let's look at some code. Uh-oh. All right. So I've been working really hard on building a lot of tools and systems for the agency. And so here is a calculator I built, right? I built this lovely calculator that can help generate invoices for our clients. and I accidentally put this calculator on our agency website, right? I accidentally put it on the agency website. And at first this could be fine, but there's some things that we might not want on our agency website. If we look at this calculator, you can see that I have entered in an hourly rate, the hours worked and our tax rate, Well, my tax rate. And then, I have these lovely calculate profit methods, this invoice client method. And our client can come to the website and they can generate their invoice. They can just say invoice client and they would get the invoice.

But they could also do two other things that I don't want them to do. What's the first rule of freelancing? What's the magic question? What's the magic question? What's your ballpark budget? What's your ballpark budget? I don't want my clients to ever know my hourly rate. I have the hourly rate in my brain. I know what I'm shooting for. I'm shooting for 250 an hour, right? But I don't need them to know that. I don't want them to know that. but the way that my code is written right now on the agency website, not only can they get their invoice, but at their little, you know, they're moving around, they're testing some things, maybe they know a little bit of it. They can also get the hourly rate, uh-oh, and they can figure out how much money I'm gonna make off of them. I don't want them to know how much money I'm gonna make off of them.

I want them to feel like I'm, please sir, may I have some more, right? I don't want them to know how much money that I'm making off of this, right? But right now, as it stands, if they're using this calculator, not only can they get their invoice, but they can get the hourly rate and the profit. Interesting. So let's look at this. This is better. I made some very small changes here. I made some very small changes here. If we look now, I set up the calculator. The client will never see me set it up. Now when they ask for their invoice, they still get their invoice, they still get the 40,000. But if they try to access the hourly rate, they get undefined. And if they try to access calculate profit, they get is not a function. Let's take a look. Let's take a look at the old code.

The old code, they were able to get the hourly rate and the profit, but this code, they can't. In this code, I have some private variables and some private methods. And once again, you'll notice the lovely sign here for the nerds that can't control themselves. They're absolutely shaking, right? I'm using the word private liberally here. We'll get to the real definitions later on. But right now, those things are undefined and they can't be found because look, look, look, look. Can you spot the difference? This turns them from being bound to the object into local variables. I went from this to let From this to let now these are local variables when I go ahead and I set up my calculator I plugged in my Hourly rate I plugged in my hours I plugged in my tax rate and I was able to set those values. I was able to set the hours. I was able to set the tax rate and I was able to set the hourly rate. However, the object that comes out of this constructor, the object that comes out of this constructor does not have an hourly rate property. So when I try to use the property down here, it's undefined. I did not set it up to have that property.

It is a local variable. And the beautiful thing about this is I can use that local variable inside, but it is not accessible to folks that are using the object. Right? So now I get the benefit of passing in my hourly rate. I can actually use my hourly rate inside my calculating profit, and I can use my rate, right? I can use my rate inside of my invoicing the client. This would actually have to be a variable, sorry. Well, sorry, the whole thing is, it just looks like a string here, but the whole thing is a variable with a template string, right? So I'm able to use the rate inside of my calculate profit, and I'm able to, I'm able to use the rate inside of my invoice client, but that rate, right? That rate is not available, right? That rate is not available to the user that has the object. So I'm able to use it, but it's not on the object itself. Okay? Now, we can see right away why this could be really helpful. Right away, this could be really, really helpful because now the calculator that's on our website, we can still generate invoices, we can still use numbers that we want ourselves, but our clients can't see our hourly rate, they can't see our calculated profit.

All it was is that simple change. Now the question is, so my client can now see their invoice. They cannot see the hourly rate. The thing we have to start thinking about is like what is this building up to? What am I trying to get to here? The hourly rate was hidden from the client, but we were still able to use it. the water boiling was hidden from the steam wand. We were still able to use it, right? Like the water boiled and created steam and the wand was able to use that steam. Just like the portafilter was able to use the steam too. Like the hole where the water goes through the coffee, the coffee was able to use the steam to generate espresso. It was also able to use that steam to push it through the steam wand, right? So the water boiling was using that steam in two areas. It was using it for making the espresso and it was using it for the wand. Now the wand did not care or even even to think about the water boiling or how that steam was created, right?

The wand just uses it. The wand says, give me steam. The water boiling does its thing and gives the steam. Just like our client. Our client can now get their invoice. They don't need to see the hourly rate. They don't need to see our calculated profit. It's all there. It's all still working, but they only get the invoice right We're starting to hide any of the complex or Unnecessary details the wand does not need to know how the steam was generated The client does not need to know our hourly rate to get their invoice, right? These complex or unnecessary details are being hidden. The really beautiful thing about this is this slowly enables us to implement things without understanding or even thinking about all of that hidden complexity. If we were all engineers at Gaggia, if we were all engineers there and we were tasked with working on the wand, do we need to know how the water boiler works? Do we need to know how the buttons on the front of the machine work? Do we need to know the exact size of the portafilter? No, all those details are important, but they are cool.

They're abstracted away from us, right? We can just focus on our task, our job at the moment, which is to fix that wand, right? We don't have to worry about the water boiling. Not to worry about the buttons, we can focus on the wand. If we come and we wanted to work on this calculator, we can focus on calculating the tax withheld and not worrying about the profit. We can just focus on the things that we need to get done. We're breaking our projects, our applications into smaller more manageable pieces of code. We don't have to worry about the huge system. We can and focus on just the pieces that we need to work on. And we can do stuff once. That's huge. We're breaking down our applications into smaller, more manageable pieces of code, but it also enables us to do stuff once. I am using the steam to make the espresso, and I am using the steam to froth my milk. Did I have to create the water boiler twice? No, I created one water boiler and then I am able to use it to make the espresso.

I'm able to use it to make my steam. Do the engineers working on the wand and need to even know how the steam is being made by the water boiler. No, they just say, give me steam and they can use it. This process of moving and hiding some more of the complex, the difficult pieces, making our programs into more manageable bits of code, making it so we can do stuff once. Alright. Abstraction is all about hiding the details and just showing what is essential. is essential. Abstraction is all about hiding the details. And showing what is essential. Right? By doing this, we can make our code more simple, more predictable, more manageable. Right, more simple, predictable, more manageable by using this abstraction, right? And so. So, we saw abstraction in play with the engineers working on the espresso machine, they only had to make the water boiler once and then any part of the espresso machine that needs the steam now has access to it. When the engineers are working on that espresso machine, they can just focus on the wand and not have to worry about the water boiler.

When they are looking at the espresso machine, like the part that makes the espresso, they don't have to worry about the water boiler, right? When we're building our agency calculator, we don't have to worry about what's happening in calculate profit if we're working on building out how to calculate the taxes. We can start to see how this makes our code more manageable. when a new engineer comes, right? When a new engineer comes, we don't have to worry about reinventing the wheel. We've already done it. We can just use the bits that we need and move on with our lives. Now this is like, these are meaty topics, right? These are hard topics, right? And the first pass, it's hard to kind of wrap our brains around them. So I'm trying to give you some examples, right? I'm trying to get the brain, the gears going. We're gonna see this stuff over and over again. We got like three or four classes, including office hours. We're gonna bring this stuff up.

So I hope the gears are starting to turn a little bit. We saw some of the four pillars. The four pillars are encapsulation and abstraction. We also have inheritance and the weird one polymorphism coming up, right? But we're starting to rely on these four pillars to bring some more manageability to our code. Now, encapsulation, we said, was the process of storing functions and their associated data into one thing, that fusion of functions and properties together into one object, right? That fusion, we said that's what encapsulation was. But why? Why the heck do we need encapsulation? Why is this process of storing functions and their associated data into one thing, a thing? Why? What is the reason? Why does this matter, right? Why does this matter? Well, when we utilize encapsulation, when we fused our data and functionality together into one object.

It made it easier to add new stuff. We didn't have to worry about all those messy parameters. We didn't have to know what was being passed to what. We were just, it was way cleaner. It was way easier to add new stuff. It made it way easier to read through our code, right? We're not looking at all these random made up stuff. Imagine if a bunch of people are adding bits of functionality, they would have all came up with their own parameter names. They they would have all come up with their own conventions. But now that it's part of the object, we can just use those object properties. So that makes it more readable in the long run. And it made it so we were not afraid to make changes. If all the bits of functionality are using the properties that are tied to the object, and we're always referencing the same things, no matter if we're calculating profit or tax or whatever, we're using those same bits of data. So we can make changes we can change the hourly rate from 250 to 300 and not lose Sweep sleep sleep. That is the beauty of encapsulation That's why we use it makes it easier to add new stuff makes it easier to read our code makes it so we're not afraid to make changes Does that make sense?

Do you understand why? Do you understand what is the reason? Do you? Does that make sense? Yeah? Yeah? Alright. Because I can't tell you how many books I read. I can't tell you how many videos I watched. In the end I didn't understand what it was. I probably used encapsulation professionally for years before I really understood like deeply what it was doing cool We also have abstraction an Extraction we are hiding the details and just showing what is essential Showing what is essential But why? What is the reason? Why do we need this abstraction? Why is it important to hide details and show the essentials? Like what is the reason?

Well, it enables us to make smaller, more manageable pieces of code. Our engineers can just work on one piece at a time and not worry about all the other pieces. We saw with encapsulation, right with encapsulation, it's easy to reuse the properties across the bits of functionality. That's why encapsulation and abstraction are so closely tied. It's really hard to have one without the other, because when we have the encapsulation, right, when we are making it more readable, when we're reusing our properties inside of our functionality when we fused our data and functionality together. We know that when we go and add a new bit of functionality, we don't have to worry about how the other bit of functionality was working, right? I don't care what was happening in that calculate profit method. I don't have to know that makes our code way more manageable over time. We're just worried about small pieces of code and we know that we're not going to break anything that's out there throughout the rest of our code base. So it helps us to split the complexity of the things that we want to build into more manageable parts. The engineers working on the wand don't have to worry about the water boiling. All right. Next class, we have inheritance and polymorphism. I'm going to give you some videos and some reading to watch that walk through those really important things. And when we come back from our break, we're gonna take a break.

And when we come back from our break, we are going to just quickly review encapsulation and polymorphism, sorry, encapsulation and abstraction. And then we are going to talk about the homework, the stuff we gotta get done this weekend, and then we're gonna move into working together. So don't disappear, put five minutes on the clock, we're gonna get a little bit more review in, a little bit more explanations, we're gonna answer some questions, we're gonna talk about the weekend, we're gonna talk about tomorrow, and then we're gonna get into working together as teammates. All right, five minutes on the clock. If you're new here, we like to take breaks. We like to hydrate. If you're able, please get up, move around, hydrate, let your eyes focus on something in the distance. Five minutes on the clock, you got this. I'm gonna run some ads so that folks don't have to sit through them when they come here. If you haven't checked in, please check in. If you're here, please just give the like and retweet on the tweet, please. All right, we're on the ads, three and five, folks. You Yeah, they ran Papa John's loves running ads on this stream. I don't know why but they always do Now groups not happening after class we're gonna have some time during class to work on the groups I mean, they all are recorded. They get put there on Twitch immediately.

And then on YouTube a little bit after it'll be on here for Twitch immediately after class. grab these links real quick All right, folks, come on back. Come on back. All right. Hope you had a good break. Let's go ahead. Let's review encapsulation. Let's review abstraction real quick, and then we are going to set up the project and we are going to move into the project. Alrighty. We ever know who won the project night? Yes, I keep forgetting to announce it. Maybe we'll maybe we'll make that something we'll announce tomorrow during our career like our story mapping class. Yeah, crafting your story. I keep pushing it. So yeah, we'll do that tomorrow.

That'll be an incentive to show up another incentive to show up tomorrow. We'll announce the project winners then. Alrighty. We also have to do some Pokemon cards too. We'll do those. I'm just gonna start doing the Pokemon cards on Sunday cause we just have more time then. Yeah. All right. Encapsulation. The process of storing functions with their associated data into one thing, right? Taking our data and our functionality, putting it into one object. Beautiful. We gotta, you gotta do the full though. You gotta do the full. Gotta do the full, right?

But why? Why do we care about tying this fusion of our data and functionality together? Well, it makes it easier to add new stuff. We don't have this big mess of procedural code, right? This big mess of procedural code where there's global variables here and functions over there. They all have different parameters. They're all using different stuff. Just hard to read. Can we do it? Yes. Can we make it work? Yes. but there's a better way when you use encapsulation. It made it easier to read through that code, right? Like we're using the same parameters over and over again.

We're using the same values. And it makes it so we're not afraid to use changes since we are reusing those values since they are all tied together. You know how your changes are going to affect the other pieces of your code. Abstraction, right? It's the idea of hiding details and showing the essentials. But why, why do we need abstraction? Well, when the individual is working on the steam wand, they don't care how the boiler works. They just want steam. Give me steam is what the engineers are yelling out. They don't need to redesign a water boiler to use the steam in the wand, right? They got a lot of things to fix in the wand. They got to change it from the two hole to the one hole to give it more control, right? So the idea is that the beauty of the steam wand, the engineer working on the steam wand, they don't have to redo the water boiling. They can just use steam, right? The boiling is abstracted away from them.

When a client is on our website, they can just get their invoice. They don't need to see the hourly rate. The hourly rate is abstracted away from them. So it enables us to have smaller, more magical bits of code. the complexity we can be hidden, not only for our clients, but for our fellow engineers, not to worry about those things, to not lose sleep at night by that encapsulation and that abstraction kind of meld together to be really helpful. All right, that's two of the big four. And I'm gonna come with more examples next class. So we're gonna have more examples on encapsulation, more examples of abstraction next class. Then we're gonna hit at the other two big pillars of OOP or Object Oriented Programming, and that's inheritance and polymorphism. So that's next class. Those are doozies, but once again, we're gonna start with why. We're starting with why, right? Then we'll get into using it and seeing like actual code using it. Tonight's about why, next class is about why, then we'll have the rest of the classes to build and actually see real code examples and how they come together. Those are big words, they are big words.

And when I first learned them, I taught them, you know what, I was like, that's a lot of disrespect being thrown around. All right. The using, does it using come before understanding? It does, that's why we've been using objects. We've been doing these bits of encapsulation. We've been using encapsulation. We've used a little bit of abstraction in class too. And so next class, we'll start to see those examples come to life. All right, group work. That's not the right remo. I don't, this remo's wrong. Don't go to this one. This one's wrong. So tonight we are going to work on a project. This project is a rite of passage for all new software engineers, and it's to build a tic-tac-toe game.

So tic-tac-toe can be done procedurally. It can be a, It can be a, thank you for the engagement. It can be a, it can be a really messy, hot, messy code base, right? You could do global variables everywhere, functions everywhere, right? But what I want you to do tonight is to get into a group and I want you to get it to work. Get tic-tac-toe to work, right? Get tic-tac-toe to work and then make it easier to add new stuff Make it easier to read through what was already coded make it so that you're not afraid to make changes so if you want to make a uh Be a baddie and write bad code and get your functions and your your variables flying and getting tic-tac-toe to work That's the start But then when i'm telling you to add when i'm telling you to make it easier to add new stuff When i'm saying to make it easier to read through what was already coded when i'm saying to make it so that you're not afraid to make changes. What am I asking you to use? What am I asking you to use? I'm asking you to use OOP. I'm asking you to use the encapsulation, to use the abstraction that we learned tonight. Go back to the slides, look at my examples. What did I change? How could you change your tic-tac-toe to utilize those examples as well? We got some homework that includes some video watching, Some reading to do and there's some push reading if you want to push remember push reading is for folks that want to push It's not required.

You want to push you can do that reading? I'm also expecting you to keep up with your code wars to keep up with your Anki and if you're gonna work with us tonight Which I hope you do come Struggle during the struggle bus together work with some other individuals join a table get lost in the sauce together Be kind to each other know that we're all here to learn Don't let your inner code weenie come out. Leave your code weenie at the door help others that are in your group We're collaborative together and get something working and then try how can we revisit this add encapsulation add? Abstraction to our code. So if you would like to join a group I've opened up three remos You can join any one of these three remos There's also the link in in in Discord is there as well. You can join one of these tables. You can work with others. Can I just watch? Sure, you could join a table. Tell folks, hey, I'm new. I'm not as comfortable with this material. I would love to interject if I can and be helpful, but do you mind if I be a fly on the wall? That's fine. Start like that, right? You're among friends.

If your goal is to get a job, you're gonna be working with other engineers. Come practice it tonight. I don't care if you're silent on Remo, That's fine. Do what's comfortable for you, right? Do what's comfortable for you. And if for some reason Remo doesn't work, we got plenty of voice channels on discord. We got plenty of voice channels on discord. Join your study community discord, join voice channels on discord. So I prefer if you're on Remo, but for some folks it doesn't, that doesn't work. So there is discord. All right. Don't run away. Come actually work on these projects together. We got to start working on projects together. We got to start working with other engineers I know streams gonna be over and some of you're gonna try and disappear Don't disappear come work with your fellow 100 devs make some friends get to know some other engineers get comfortable working with others Find your comfort level and get in there start slinging some code Already folks Ronin send me a name.

I need a name If people are being toxic, just send me names. I need them. That's not the community as a whole, but every once in a while, there's a code weenie that just can't help themselves. That's what mod mail's for. All right, folks, be kind, be baddies, write bad code, and then figure out how you can apply OOP to it. We're not doing a raid. We're jumping right into Remo. So you can jump into any of these Remos. There's three of them there. Jump in. I'll see you over there. I'm gonna be bouncing through them, saying hi, stopping at different tables. And, uh, have a wonderful rest of your day. I will see you tomorrow on discord for crafting your story live. All right, folks, we got about an hour left in class.

Let's get on these remotes. Let's work together. Let's build tic-tac-toe. All right, folks. See you there in a few seconds. No raid. Just going to see you on Remo. Peace everyone.

End of Transcript