Object-oriented Programming in 7 minutes | Mosh
- December 21, 2023
- Posted by: MainInstructor
- Category: JavaScript
![*](https://i0.wp.com/allprowebdesigns.com/wp-content/uploads/2023/12/1703195817_maxresdefault.jpg?resize=840%2C430&ssl=1)
Video Title: Object-oriented Programming in 7 minutes | Mosh
A popular interview question concerns the four core concepts in object-oriented programming this concepts are encapsulation abstraction inheritance and polymorphism let’s look at each of these concepts before object-oriented programming we had procedure of programming that divided a program into a set of functions so we have data stored in a bunch of variables
And functions that operate on the data this style of programming is very simple and straightforward often it’s what you learn as part of your first programming subject at a university but as your programs grow it will end up with a bunch of functions that are all over the
Place you might find yourself copying and pasting lines of code over and over you make a change to one function and then several other functions break that’s what we call spaghetti code there is so much interdependence e between all these functions it becomes problematic object-oriented programming came to solve this problem in object-oriented
Programming we combine a group of related variables and functions into a unit we call that unit an object we refer to these variables as properties and the functions as methods here’s an example think of a car a car is an object with properties such as make model and color and methods like start
Stop and move now you might say what marche we don’t have cars in our programs give me a real programming example ok think of the local storage object in your browser’s every browser has a local storage object that allows you to store data locally this local storage object
Has a property like length which returns the number of objects in the storage and metals like set item and remove item so in object-oriented programming we group related variables and functions that operate on them into objects and this is what we call encapsulation let me show
You an example of this in action so here we have three variables base salary over time and rate below these we have a function to calculate the wage for an employee we refer to this kind of implementation as procedural so we have variables on one side and functions on the other side
They’re hard decoupled now let’s take a look at the object-oriented way to solve this problem we can have an employee object with three properties a salary over time and rate and a method called get wage now why is this better well first of all look at the get wage
Function this function has no parameters in contrast in a procedural example our get wage function has three parameters the reason in this implementation we don’t have any parameters is because all these parameters are actually modeled as properties of this object all these properties and the get wage function
They are highly related so they are part of one unit so one of the symptoms of procedural code is functions with so many parameters when you write code in an object-oriented way your functions end up having fewer and fewer parameters as Uncle Bob says the best functions are
Those with no parameters the fewer the number of parameters the easier it is to use and maintain that function so that’s encapsulation now let’s look at abstraction think of a DVD player as an object this DVD player has a complex logic board on the inside and a few
Buttons on the outside that you interact with you simply press the play button and you don’t care what happens on the inside all that complexity is hidden from you this is abstraction in practice we can use the same technique in our objects so we can hide some of the
Properties and methods from the outside and this gives us a couple of benefits first is that we’ll make the interface of those objects simpler using an understanding an object with a few properties and methods is easier than an object with several properties and methods the second benefit is that it
Helps us reduce the impact of change let’s imagine that tomorrow we change these inner or private methods these changes will leak to the outside because we don’t have any code that touches these methods outside of their containing object we may delete a method or change its parameters but none of
These changes will impact the rest of the applications code so with abstraction we reduce the impact of change now the third core concept in object-oriented programming inheritance inheritance is a mechanism that allows you to eliminate redundant code here’s an example think of HTML elements like text boxes drop-down lists checkboxes and so on
All these elements have a few things in common they should have properties like hidden and inner HTML and metals like click and focus instead of redefining all these properties and methods for every type of HTML element we can define them once in a generic object call it HTML element and have other objects
Inherit these properties and methods so inheritance helps us eliminate redundant code and finally polymorphism poly means many more means form so polymorphism means many forms in object-oriented programming polymorphism is a technique that allows you to get rid of long ethanol’s or switch and case statements so back to
Our HTML elements example all these objects should have the ability to be rendered on a page but the way each element is rendered is different from the others if you want to render multiple HTML elements in a procedural way our code would probably look like this but with object orientation we can
Implement a render method in each of these objects and the render method will behave differently depending on the type of the object you’re referencing so we can get rid of this nasty switch and case and use one line of code like this you will see that later in the course so
Here are the benefits of object oriented programming using encapsulation we group related variables and functions together and this way we can reduce complexity now we can reuse this object and do from parts of a program or in different programs with abstraction we hide the details and the complexity and show only
The essentials this technique reduces complexity and also isolates the impact of changes in the code with inheritance we can eliminate redundant code and with polymorphism we can refactor ugly switch case statements well hello it’s me mash again I wanted to say thank you very much for watching
This tutorial to the end I hope you learned a lot please share and like this video to support me if you want to learn more about the object-oriented programming as I told you before I have a course called object-oriented programming in JavaScript if you want to
Learn more click on the link in the video description and enroll in the course if not that’s perfectly fine make sure to subscribe to my channel because I upload new videos every week thank you and have a great day
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Currently on this topic in the Front End Developer Course by Meta. It’s amazing how I’m slowly being able to understand such topics lol
thx
Jesus is Lord and he is coming soon
Stop watching at encapsulation delete this video pls
OOP is so broken. For beginner almost impossible to understand someone's else code.
After watching this video… I still know nothing.
These youtube videos better than UNI classes. Thanks thanks thanks! 😍
Amazing explanation!!
cool like so!
The second benefit of abstraction sounds like a benefit of encapsulation to me
Sir u are the Don ….. Of programming
fffgghhhhh
Incorrect Incorrect Incorrect
You have confused abstraction and encapsulation!!!!!
Hiding the properties with the use of access modifiers is Encapsulation.
Selecting relevant attributes and rejecting the irrelevant ones in Abstraction.
great quality content, but as soon you subscribe to their website they keep charging you even after unsubscribing. they don't let you delete your credit info and respond the way it is our fault, like we can do anything about the autorenewal, not fix their website issue which is not secure and reliable to add credit info.
hi mosh you are best trainer ….thank you for sharing your skills with us..
I know nothing about technology, and I have an essay on the 5 programming languages, thank you for explaining it where I actually understand
Encapsulation is data[information] hiding. Eg clicking picture through smartphone camera by touching button on smartphone interface or In a video game, the player's character might be implemented as an encapsulated class with private attributes like health and position and public methods like move and attack. and Abstraction is Detail[implementation] hiding Eg In a banking application, you might have an abstract Account class that defines methods like deposit and withdraw without specifying how each type of account (e.g., savings, checking) implements these methods.
After meticulously following tutorial I encountered unforeseen errors impeded progress raises concerns accuracy completeness guidance
Your argument nt seem consider potential ramifications adequately
Your code nt seem adhere technical naming conventions potentially leading confusion among developers work
Your code nt follow principles clean code