From the course: Treating Go as an Object-Oriented Language
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Structs as classes - Go Tutorial
From the course: Treating Go as an Object-Oriented Language
Structs as classes
- [Instructor] Go is not an object-oriented language as I just stated. But the first similarity that we can leverage while treating Go as a pseudo object-oriented language is through the use of structs as classes. Now, let's first talk about a class in OOP. My assumption here is that you have familiarity with the paradigm, so I will keep this very high level. At its core, a class is a template for an object. A class has attributes or variables that are part of the object when it is created. A class also has methods or functions, and these procedures can act on the data within the class within that object or can act external to that. And while many languages provide classes, they all ultimately are user defined even if that user was one of the core library developers. So classes other than the base class are always user defined. So let's talk about Go structs and how they're similar to classes. Go structs, like classes are…
Contents
-
-
-
-
(Locked)
Structs as classes2m 21s
-
(Locked)
Creating a struct5m 16s
-
(Locked)
Encapsulation2m 43s
-
(Locked)
Leveraging encapsulation5m 35s
-
(Locked)
Solution: Struct as class2m 2s
-
(Locked)
Composition1m 36s
-
(Locked)
Leveraging composition4m 11s
-
(Locked)
Polymorphism2m 59s
-
(Locked)
Leveraging polymorphism4m 49s
-
(Locked)
Solution: OOP4m 56s
-
(Locked)
-