HomeЛюди и блогиRelated VideosMore From: Programming with Mosh

Object-oriented Programming in 7 minutes | Mosh

6587 ratings | 239232 views
🔥Get the COMPLETE COURSE: http://bit.ly/2keDCna 4 pillars of object-oriented programming: encapsulation, abstraction, inheritance and polymorphism. Subscribe for more videos: https://www.youtube.com/channel/UCWv7vMbMWH4-V0ZXdmDpPBA?sub_confirmation=1 Want to learn more from me? Check out my blog and courses: http://programmingwithmosh.com https://www.facebook.com/programmingwithmosh/ https://twitter.com/moshhamedani
Html code for embedding videos on your blog
Text Comments (218)
Kuya Frex (1 day ago)
I'm already applied these concepts in my code without even knowing the terms for that. At least now I know
avimukta1 (2 days ago)
Is this suitable for beginners?
No, you should start from my JavaScript for Beginners course.
Ralfie Library (3 days ago)
Great, thank youuu
Shivashish Tripathi (4 days ago)
Thanks
Rehan techie (5 days ago)
At 3:16 you said oop does not require parameters, but just after calling the function down we can see parameters. Why?
Smart Programming (7 days ago)
nice explanation sir, thank you 👍👍👍🙂🙂🙂
Neon Prince (8 days ago)
Tesla has Car's in their code lol
Erron Intila (8 days ago)
Thank you Mr Hamedani 😀
KUNAL SHAW (10 days ago)
he sounds like Nadeking!
Crypto Chan (12 days ago)
damn dude great tutorial.
Omar Salama (14 days ago)
what is this vcCode theme name?
Programming with Mosh (13 days ago)
Ayu Mirage
Neo Take (16 days ago)
is this Java ? and what is that programm u are using ?
Sergio Díaz Nila (18 days ago)
This entire video is a strawman because Object Oriented Programming is one type of Procedural Programming, even with the mistaken definition you have used, your methods are procedures with a default argument, which you can access via the keyword "this". The term procedural programming is derivative of the term procedural knowledge, which is always contrasted to declarative knowledge from which the term declarative programming derives. Procedural knowledge is any knowledge that is expressed in terms of a cookbook recipe, an algorithm, sequence of steps to follow, so is a description of "how" to do/get/make something. In contrast declarative knowledge is describes the "what" is something, for instance you provide properties you can test, a goal to reach. Examples of procedural programming are Structure Programming (like C & Pascal) or Object Oriented Programming, Actor Model, DataFlow Programming, etc. Declarative paradigms would be Logic Programming, Constraint Programming, etc. Also your definition of Object Oriented Programming is bogus & wrong, those 4 "pillars" are secondary to Message Passing, that is the key foundational principle of Object Oriented Programming, if you don't understand that, you don't understand OOP at all, then you would be using ADTs (abstract data types) with a convenient syntax, & that's all. In contrast what you are saying is what Bjarne Stroustup understood of Simula, filtered by the C++ community, skined with the terms of Alan Kay, not even his ideas just the words, so it is a sham, and you are defrauding people. And if this isn't your intention then please do research. Alan Kay explained what OO was in 1972 but only very few people understood him, those that knew Functional Programming back then, and Carl Hewitt that made the best implementation of the ideas that Alan Kay communicated, the Actor Model. Carl Hewitt understood in concrete terms, what Kay was explaining with abstractions. When Alan Kay came up with the idea of OOP, he wasn't thinking in Simula, he was thinking in a network of biological cells, in biological tissue, operating a large function by passing messages among each other. He thought of Simula until he was considering the implementation in code, but even before Simula it was LISP. This is a terrible explanation. That type of encapsulation is nonsensical if you had actually wrote a single line of code in your life you would understand it, because when you use a getter or a setter you are piercing that "encapsulation" and usually those properties are other objects, and the actual state is not held within the supposed object encapsulating it. Why the name "methods"? the term methods came because of message passing, an object which is an entity that is able to receive and send objects, may have multiple ways(methods) to interprete a received message. There is a message selector, and the object internally has a multiple methods for that message, that means the object in itself may have dispatching of its own. What encapsulation means it is what Joe Armstrong refers as Isolation, Alan Kay has given a great example of what his invention is, Encapsulation is when you have a computer X in the internet, and it may fail but every other computer that is connected to X, doesn't fail just because X fails. Alan Kay also explained what was his idea of an Object, as i said before is an entity that sends/receives messages, but his inspiration was a mechanism of machines of the 60s, that communicated by sending files divided in 3 sections, the 1st section was a header with pointers to elements of the 2nd & 3rd section, the 2nd section was the code meant to process the data contained in the 3rd section. Your argument of the "too many parameters makes code difficult to maintain" is nonsense in Javascript, because you can use closures for partial application and reduce the number of parameters you carry around. also because a good source code editor would have autocomplete and that helps. If you learn FP techniques, what you would call "design patterns" then all of your arguments are empty & make no sense which show you are a total n00b.
daniel rodney (22 days ago)
متشکرم
abheeth kotelawala (22 days ago)
Getting ready for my first interview Thank You!
Kamil Wiśniewski (23 days ago)
"We can change or modify one of the methods and it will not impact the rest of the code" - famous last words ;) Class extending, sharing "this" all around the place, mutating the state - that's all the consequences of OOP and it WILL impact the whole program. Granted - it's all about the patterns. But we all know how you can end up with "Spaghetti" code even with OOP. Not to mention presented "Procedural" programming claims should be also contrasted with Functional Programming since Procedural would focus highly on imperatives rather than abstraction functions. Beginners could easily confuse Procedural with Functional at this point. With that being said - thanks for gr8 video :)
Kristupas Antanavicius (24 days ago)
This video is horse shit. Functions with no parameters are better than functions with parameters? Are you joking? Congratulations, you have just created a function which can't be reused in other contexts and which has unknown data dependencies. Now imagine your "localStorage" object implementation in Chrome, which probably has at least 2k lines of code and 100 member variables, and tell me that a function in such a class would be better of without parameters.
Yousif Johny (27 days ago)
Brilliant Video!
terminalcommand (27 days ago)
I love ya' Mosh - great content!
Programming with Mosh (27 days ago)
Thank you! Please support me by sharing this video on the social networks you use so others can learn too. And be sure to subscribe to my channel for more videos like this.
Omni Ed: Garry's Mod (1 month ago)
To be fair you forgot to say why OOP is worse than Procedural: -OOP is inefficient due to communicating with inheritance hierarchies. -OOP requires more lines of code on average thus more opportunity for errors. The Uncle Bob quote is a fallacious argument from authority.
Programming with Mosh (29 days ago)
Are you saying procedural programming is better than OOP?
Santosh Shrestha (1 month ago)
i m still not clear on encapsulation can anyone help me?
Olimhon 31 (1 month ago)
He explained in a difficult way
dirtdirt (1 month ago)
Best example of encapsulation I've ever seen, thank you
Programming with Mosh (1 month ago)
Thank you! Please support me by sharing this video on the social networks you use so others can learn too. And be sure to subscribe to my channel for more videos like this.
Claudia Sastrowardojo (1 month ago)
what kind of software i can make this kind of presentation?
Ketan deshmukh (1 month ago)
Really amazing
Max Power (1 month ago)
Clear, complete and straight to the point, thanks!
Max Power (19 days ago)
+Sergio Díaz Nila Didn't know that, thanks for the tip Sergio!
Sergio Díaz Nila (20 days ago)
actually is very bad, and disinformation. Is the classic spiel you get in every collage with lazy teachers, that don't inform themselves. It is born out of a misinterpretation of Alan Kays work on Object Oriented programming, very few people understood Alan, like Carl Hewitt who made an excellent concrete definition with the Actor Model. If you want to understand OO, google about Carl Hewitt, read his papers, listen to his talks and read the material he suggests. The very core concept of OOP is Message Passing, in an Interview Alan Kay said he regretted to call it OO because people has missed the point of messages, when he invented OO he was doing it taking inspiration of networks of biological cells, achieving some objective by communicating passing messages to each other. What this video explains is procedural programmers projection of their mistakes working with languages like C, Pascal, Assembly code. And this reduced OO from an awesome Actor Model to a simple convenient syntax sugar for Abstract Data Types.
shouldn't the arrows go out from the HTML-elements box into the other objects if they are inheriting from it? :) Love the video!
Shihab Ahmed (1 month ago)
am so confused after watching this video
Aks Byte (1 month ago)
Wow
Ismail Vittal (1 month ago)
Every computer science lecturer should watch and understand this video before confusing the students. Thanks Mosh Bro.
Programming with Mosh (1 month ago)
Thank you! Be sure to subscribe and please support me by telling others about my channel. :) I also have a blog at http://programmingwithmosh.com
JAY SAMANI (2 months ago)
C, C++, Java, JavaScript, C#
Max J. (2 months ago)
actually a great video. thanks!
Programming with Mosh (2 months ago)
Also, keep an eye on my blog http://programmingwithmosh.com
Programming with Mosh (2 months ago)
Thank you! Please support me by liking and sharing this video, and subscribe to my channel! :)
Ravuri Vivek (2 months ago)
Can you teach .Net course?
Programming with Mosh (2 months ago)
I have several .NET courses. http://codewithmosh.com
Ravuri Vivek (2 months ago)
I am confused about so many definitions of inheritance and polymorphism could you please tell me the proper definitions for both of them.
Programming with Mosh (2 months ago)
You should watch my C# Intermediate course. There, I've covered these in detail with real-world examples in C#. http://codewithmosh.com
JAY SAMANI (2 months ago)
Can someone explain me abstraction with real-world programming language example? I mean just give me a real-world programming language example.
Jonathan Dansie (12 days ago)
If you have ever compiled a program, that is abstraction. The machine language is abstracted by the compiled language which is much harder for humans to parse and see all of the logic flows in. Abstraction goes in layers from the hardware up. You don't want to individually address registers. The picture of the lamp wires going into the electrical socket was a good real world example of what lack of abstraction looks like - without a plug interface to go into a socket interface you lose the correct fit and safety a plug provides.
Programming with Mosh (2 months ago)
What programming languages are you familiar with?
OrcButter (2 months ago)
I think I can relate it to making a procedure in python and importing it for use in the main program. Tell me if I'm wrong.
Andrea Vucetich (2 months ago)
This is the best, clearest explanation I've seen so far... Thank you!!!
Programming with Mosh (2 months ago)
Thank you! Please support me by liking and sharing this video, and subscribe to my channel! :)
SAM CANNON (2 months ago)
The best video on internet to learn this topic... subscribing...
Programming with Mosh (2 months ago)
Thank you! Please support me by liking and sharing this video, and subscribe to my channel! :)
himanshu (2 months ago)
OH YES SUBSCRIBED !
Programming with Mosh (2 months ago)
Welcome aboard!
Omar Khan (2 months ago)
Love this video! But what software did you use to put this all together?
Devon Marantz (2 months ago)
Such an informative and concise video! Thanks Mr. Mosh. Cool jacket btw.
Dimitar Mihov (2 months ago)
As a person who has bought the complete Mosh courses i must say that the paid content is EVEN MUCH better and i highly recommend anyone to purchase his courses. This is not a sponsored post, i have not received a damn $ from Mosh but i truly wish i had found his courses when i was learning .NET development at first!
l0calher0 (1 month ago)
Yeah, I've bought a few Mosh courses. Can definitely vouch.
Programming with Mosh (2 months ago)
Thank you so much for your recommendation! :)
steve smith (2 months ago)
great explanation, especially the first part that showed a practical example with the localStorage. I watched a few other videos that tried to explain OOP concepts and it just left me confused. I think where I get bored with watching coding videos is when they don't use enough practical examples.
Programming with Mosh (2 months ago)
Thank you! Please support me by liking and sharing this video, and subscribe to my channel! :)
Shubhranshu Chourasia (2 months ago)
Thanks to you to clear all my doubts regarding oop
Programming with Mosh (2 months ago)
Thank you! How much programming experience do you have? What are your goals?
ateng lenon (2 months ago)
simple analogy comes from the person who understand it.. and you made oop become clear.. thank you..
Programming with Mosh (1 month ago)
Thank you!
ateng lenon (2 months ago)
done, without any doubt.. :)
Programming with Mosh (2 months ago)
Thank you! Please support me by liking and sharing this video, and subscribe to my channel! :)
ahmad nikidos (2 months ago)
Great vid, tks i understand but still confused 😂😂
Adi 24 (2 months ago)
Great!
BigBMrBenben (2 months ago)
You down with OOP?! Yeah! You know me!
Benjamin Krall (2 months ago)
What an awesome video
Ernist Isabekov (2 months ago)
makes confuse, in some book say OOP base on 3 parts except abstraction
Alvaro Neto (2 months ago)
Great vid, thank you Mosh!
Nate Herder (2 months ago)
Very informational, thank you sir!
Programming with Mosh (2 months ago)
Thank you!
Recreation Moments (2 months ago)
Easy to Understand.....
Robust Misconception (2 months ago)
Content was great, and I thank you for that!! But those bright colors cause migraines lol
Abby Marie (2 months ago)
loved the colours - migraines cause migraines!
Programming with Mosh (2 months ago)
Thank you! Will keep your feedback in mind. :)
Maciej Patej (3 months ago)
Finally someone explains it casually and clearly! Thanks a lot!
Mohammed Amine (3 months ago)
i feel like i skiped 1 year of OOP courses on univercity in 7min
Programming with Mosh (2 months ago)
What they teach in universities about OOP is anything but OOP! You should read my post here: https://programmingwithmosh.com/general/dont-need-college-degree/
Mr Toxic (3 months ago)
Why the fuck are you talking about HTML ? fuck sake its not a programming language you stupid spagheti man its a hyper text markup language that's it damn it
Prince Adom (3 months ago)
1:18, I thought car is a class and an instance of this car class is for example say Ford?
Programming with Mosh (3 months ago)
Terms "class" and "object" are often used interchangeably. But technically Car is a "class" and and an instance of that like the car you drive is an "object".
Andrey Vasilyev (3 months ago)
Very grateful for your work on this clear, pleasant and informative video. I am new to programming and decided to start off by learning Python. When I began learning about it I found out it is a object-oriented language and scratched my head not understanding what that even implies... After watching this video, I can now go back to learning with clarity. Thank you! Subscribed and thumbs up!
Programming with Mosh (3 months ago)
Thank you! Please support me by liking and sharing this video, and subscribe to my channel! :)
MOHSINWORLD (3 months ago)
Which themes are you using on PHPStorm?
Rogier van Gemert (3 months ago)
spaghetti code also exists in OOP, by all the inheritances and polymorphism... even more so in reality. (there is a movement going that want procedural back, and not without reason.. our brain is not made for oop, but for logic. step for step elements. This is what OOP doesn't allow, because of all the added bloat, bloilerplating. (which confuses more than bring clear logic) Think about encapsulation, inheritances, heck even mutliple inheritance. Sure, OOP simplyfies the use of those objects, but that only when the classes and methods etc etc etc are set in place. Creating these is hard (you need to think more about the flow in contrast to procedural) and confusing as many pro programmers will tell you.) Yes, i am not so thrilled about the OOP world... myself.. although i do not hate it either....
Theme Roller (3 months ago)
No code example for abstraction, inheritance and polymorphism? I dont understand your video.
acar lele (3 months ago)
I think you have misunderstanding about encapsulation and abstraction
Programming with Mosh (3 months ago)
No, my friend! You were not taught OOP properly. Encapsulation = combining data and functions that operate on the data in one unit (class). Abstraction = abstracting (simplifying) the interface of a class by hiding some of its members (using access modifiers like private).
ThePowerchimp (3 months ago)
I think you defined ABSTRACTION wrong. Abstraction is boiling an object down to its pure purpose. EG - To abstract that complex DVD player with all its electronic innards, we think of the object as simply "This object plays DVDs" - ignoring its uniqueness - color, size, brand, weight etc or how it works, just that its core purpose is "to play DVDs" - that's abstraction. You sort of described Encapsulation twice. Correct me if Im wrong.
Damon Martin (3 months ago)
Think about looking on an underground map and you see loads of different lines to travel but you only care about one of them so you ignore the rest only focusing on that line to travel on as that is the only one relevent. That is an example abstraction a way of thinking ignoring usless details.
Programming with Mosh (3 months ago)
You got it wrong my friend. I don't blame it on you. There is a lot of bad information about object-oriented programming. Abstraction is exactly what I explained. Read this too: https://stackify.com/oop-concept-abstraction/
ThePowerchimp (3 months ago)
OK, there may be some overlap in our definitions here, so I'd like to clarify as I'm still learning this stuff! If you imagine a four-door, pale blue, sedan with white-wall tires and roof-racks, ABSTRACTION would have you call all that simply "CAR". That is, whatever may or may be unique about the vehicle, at its purely functional purpose level - it's a "CAR". That's how I understood abstraction - yes its about simplification conceptually, but "hiding its details" is part of... ENCAPSULATION - is akin to taking those doors, wheels, roof-racks etc and isolating them solely to the "CAR" so they don't appear to any other object. You "encapsulate" those details within the "abstracted" CAR, making them invisible to other vehicles, so they only relate to "CAR", creating a CAR class. If you could use my analogy of the car to explain where I'm wrong, Id appreciate it to improve my understanding. Thanks - great video btw.
Programming with Mosh (3 months ago)
No, I didn't. Abstraction is about hiding the details and the complexity. It's about simplification. That's when you hide some of the members of a class by making them "private". Encapsulation is about combining data and functions that operate on the data into a single unit called class.
Enzo Jen (3 months ago)
Thank you ! I am simple to understand the OOP.
APEX KILLA (3 months ago)
What theme are you using? Really love it...please tell me😁😁
Programming with Mosh (3 months ago)
Ayu Mirage
بهنام محمدی (3 months ago)
very good
Joe Legg (3 months ago)
Great Video! What theme are you using for visual studio code?
Programming with Mosh (3 months ago)
Ayu Mirage
darkangel2327 (3 months ago)
Thanks for the great explanation.
giang khuat (3 months ago)
Hi sir may I ask which app you used to make the video ? Thank you ! I would really appreciate it
Uday Bhaskar (3 months ago)
Joe Armstrong Said and I firmly believe. The problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.
Programming with Mosh (3 months ago)
Blame the coder, not the programming language. Give the best language to a bad coder, they will make a mess.
Hesam Gholami (4 months ago)
Very nice and sweet animations, thanks for this tutorial
Mike Kevin Castro (4 months ago)
That was so beautiful. I love you.
Programming with Mosh (4 months ago)
Thank you! Please support me by liking and sharing this video, and subscribe to my channel! :)
David schreiter (4 months ago)
Wow. concise and informative. Instant sub!
Thom Ives (4 months ago)
This is VERY well done - thanks!
Programming with Mosh (4 months ago)
Thank you!
rany21 (4 months ago)
Well done. Thanks for sharing this content. Simple and easy to follow.
Programming with Mosh (4 months ago)
Thank you! Please support me by liking and sharing this video, and subscribe to my channel! :)
Thahaliya Yasmin (4 months ago)
Awesome
Harsh Patel (4 months ago)
love you Mosh ... and yours all tuts ..<3 i m huge fan you
Mr Offensington (3 months ago)
I love him more.
Programming with Mosh (4 months ago)
Thank you! Please support me by liking and sharing this video, and subscribe to my channel! :)
0x1A3C3E7 (4 months ago)
It's a good presentation of theory but, the theory is wrong. Functions are a form of encapsulation. Function templates are a form of abstraction and polymorphism that supports code reuse without all the conceptual and textual overhead of classes. If you follow good programming practices, it's easy to keep procedural code neat and organized and easy to read and comprehend. Otherwise you can just as easily end up with a big confusing hierarchy of classes full of long ugly names that make it impossible to comprehend the overall architecture of the program. That's what UE4 is right now.
swatllama tBMC (2 months ago)
OOP is generally not a good solution, but UE4 is one of the best examples of how to do it properly.
paramatman21 (3 months ago)
The encapulation theory confused me slightly and I think it's in part due to static declaration of the employee member variables. Is there any added benefit apart from code cleanliness? What if I have an array of 500 employees with an added employeeType variable (contractor, fulltime)
Patrik Holmberg (4 months ago)
Forgive my ignorance but wouldn't the OOP-way break more easily than the procedural way? Example: If we use your method "getWage(baseSalary, overtime, rate)" and decide to copy the method to another project it would work just fine - it returns a calculated value. But if we were to copy the OOP "getWage()" we'd have to copy the "baseSalary, overtime, rate"-properties as well just to make the method work.
Patrik Holmberg (4 months ago)
It does. Thanks for the reply!
Programming with Mosh (4 months ago)
In object-oriented programming, you think in "objects" rather than "functions". So, if you want to copy your code, you should copy the entire object. Makes sense?
asjkdvk (4 months ago)
You need to learn more programming before starting to teach it.
Kendall Gibson (4 months ago)
This was super helpful, thank you!!!
Programming with Mosh (4 months ago)
Glad you liked my tutorial! Keep an eye on my blog too. I'm planning to publish more articles. :)
Erik Schiegg (4 months ago)
Hey, if you you watch the video in double speed, you master oop in even three and a half minutes!
Ahmed Tamer (9 days ago)
It worked actually xD
ZHI NA (4 months ago)
Excellent. Tnk u a lot a lot alot
Ruslan Kardashev (5 months ago)
What about Delegation?
Vic Shóstak (5 months ago)
Hello Mosh! Would be great to have your course about GraphQL (React + Django, for example) :)
me nefcanto (5 months ago)
I bet you're Iranian. Your accent shouts that.
R V (5 months ago)
Thank you! You should do one on functional programming too 🤓
Programming with Mosh (5 months ago)
Sure, in the future!
Cryptic Coding (5 months ago)
What Software You Used To Make The Animation At the Beggining Of This Video
Lucas Guilherme (5 months ago)
OOCSS fits in OOP? Sorry if it's a noob questions I am a extremely new in the subject
Neil Roy (5 months ago)
A wonderful work of fiction. You made it appear as though I don't have to write any code at all for polymorphism. Show people all the class code required to get it working. I prefer the simpler switch() in C. I can have a function, and call it with one parameter which then uses the switch() or whatever to act upon it. I actually wrote C code (not C++) for buttons for a game I made, and it was fairly simple to implement and check them, and without any switch() statements at all. Just a single call.
VISHWAJEET - (6 months ago)
very good video.... help me lot... thank u so much...
Son Goku ssj4 (6 months ago)
Oh hey! Another car example... This video is sh*..... ""then few seconds happen"". Wow, he's telling a practical use case! No way!!! ""at the end"" - the DVD player was a great comparison. And you even mentioned other important things... VERY nice. For now, one of the best videos out there to understand, at least for a small part, what's OOP.
Chrysippus (6 months ago)
In your example code around 3:00 the baseSalary variable has a value of 30_000. Is the underscore ignored? I've never seen this in production and can't find any spec for this 🤔
Blasturthoughts (5 months ago)
In swift we use underscore instead of commas
Ирвин Уэлш (5 months ago)
Just tried it. Id doesn`t work, by the way. The error is being thrown
CodeTicks (6 months ago)
This video saved me from trifling things.
Shashank Rajesh (6 months ago)
Very nice explanation, thanks!
Akanbi Segun (6 months ago)
I watched your full tutorial on react before my system crashed, and I lost everything. Ever since, I've been looking for this channel, so glad I did. And I won't forget to subscribe cos I did even before watching this video. P.S: Your tutorials are great and keep up the good work.
tony hoss (6 months ago)
awesome
Vishal Sinha (6 months ago)
Love the colorful presentation!
elgorial (6 months ago)
Which code editor and syntax theme was that?

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.