Is Golang Object Oriented!? (OOP)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you google search for golang and turn your head to the wiki page on the side here as you can see it says object oriented wow wikipedia blatantly lied sort of in today's video i'll explain why go is actually not an object-oriented programming language as it says on a wikipedia here [Music] now if you've ever heard about object-oriented programming or oop for short you must also have heard how powerful this programming paradigm is it is a part of the foundation for modern software engineering prior to object-oriented programming had been invented and dominating the whole industry procedural programming was the norm instead now a procedural programming is where you divide your program into mostly functions and these functions operate on variables accessible within these functions or you can call other functions however this type of a programming paradigm can get messy very quickly as the program that you are coding grows you might find yourself a copying and pasting code snippets all the time or you are creating dependencies among these different functions like spaghetti making one single change in a function may seem fine at first but may actually end up breaking everywhere else because there isn't a great way of managing these different functions in a organized manner and this is what exactly urged the invention of object orientated programming the idea was instead of having all of these functions i keep on calling other functions in all directions we can organize them more in terms of a real-life object that people can actually wrap their head around on top of that we can apply common and modern design patterns to make our code base even more comprehensible now object-oriented programming has a four main features abstraction to obtain an abstract view of a real life of problems without unnecessary details encapsulation to keep some attributes private while others accessible polymorphism the ability to unifiedly refer to things that actually have different underlying reforms inheritance the ability to use the data and implementation of another object as time went on object-oriented programming actually became the golden standard universities started including it as one of the must-haves in the school's curriculum giant tegan corporations has started promoting it as a best practice and you can barely work for any one company that doesn't use it one way or the other oop became a default way of life for many developers however as you can probably already guess everything has its pros and cons even though object-oriented programming has gotten popularity like no other there are also many pitfalls of this particular programming paradigm inheritance in particular even though it is one of the main features of object warning data programming lives on the very forefront of all of these potential problems in front of us we have a summer very simple java code to demonstrate how inheritance works we have a three different classes the first one is a regular human that has the method of a chill which we'll just print out chilling the second class is the ninja which extends the regular human class which means we would have the accessor to call the choke method here as well as the added attack method that says throwing a ninja stars lastly we have the senior ninja class which extends the ninja class which extends the regular human class which means that any senior ninja objects will be able to call the method of attack as well as a chill because these two classes are super classes of the senior ninja class as you can see with the usage of inheritance you gain the ability to use the data in the implementation of a method from another class or other classes however at the same time we are also creating very tight coupling among these different classes if anything it changes in a basic class it could potentially break all of its subclasses and it does in many cases especially if you have new developers coming in and out of the projects in the code base ones that are now doing the coding or doing the code reviews may or may not have the full context of how these classes were intended to work originally while inheritance often can save us quite a few lines of instruction it also has a tremendous potential danger so what's the solution then and more importantly how does a go in particular address this type of problems go in fact does not have all four features of object-oriented programming fully implemented go actually does not have the concept of inheritance allo instead gold developers are recommended to use composition over inheritance to demonstrate composition we have a somewhere very simple her goal angle in front of us right off the bat i want to point out there isn't even a keyword that works similarly as extends in java so there isn't even a way for us to use inheritance what we have instead as you can see are the same three main structures regular human ninja and a senior ninja instead of inheriting the implementation implicitly we are doing so explicitly by having the super class as a member variable instead and when we are trying to implement the same method we are explicitly calling the same method coming from the original superclass by doing so we gain the flexibility on how we want to use the functionalities of our superclasses also when we update the implementation of the original super class we don't have to reorganize all of the implementation of our sub classes at least compared to java what's also especially interesting about go is its take on a polymorphism and interfaces more specifically goals support duck typing duck typing is if it walks like a dog and a quacks are like a dog then it must be a duck leveraging on the context from all of our previous examples if we have an interface of a type of regular human and a struct of a type ninja as long as the ninja struct implements all of the functions that is in the interface regular human then the ninja structure must also be of a type regular human aside from that there are so many more interesting attributes of a golang interfaces since interfaces in go are so much more powerful compared to other languages but it's a little too much to cover in this same video i might make a separate video to go over golang interfaces a lot more in depth so just let me know if that's something you ninjas are all interested in now at this point and some of you might argue that object-oriented programming is more of a style more of a state of mind when you are structuring your code any programming language does not have to have all four of the features of oop in order to be considered as a oop language for those of you i want to say it's a totally fair for you to ignore all of the information i've tried giving you so far in today's video and comment in the comment section down below that wallers is a dum-dum on the other hand if you found this video informative or helpful then make sure to like this video subscribe to the channel and turn on the notification bell to become a golang ninja go to golangdojo.com to get started and i'll see you ninjas in the next video [Music] you
Info
Channel: Golang Dojo
Views: 2,150
Rating: undefined out of 5
Keywords: golang, golang 2021, learn golang, go lang, golang in 2021, go language, golang tutorial, go programming, golang for beginners, Is Golang Object Oriented!? (OOP), golang oop, golang object oriented programming, oop languages, golang oop langauge, oop golang, object oriented programming languages, object oriented programming golang, golang object oriented, go object oriented, object oriented programming tutorial, oop tutorial, golang oop tutorial, object oriented golang
Id: 7D1W15cR_Hc
Channel Id: undefined
Length: 9min 10sec (550 seconds)
Published: Fri Nov 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.