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.
Encapsulation - Go Tutorial
From the course: Treating Go as an Object-Oriented Language
Encapsulation
- [Instructor] Encapsulation is a primary pillar of object-oriented programming, and something that we get in Go as well. Encapsulation is a very important concept, especially when writing libraries. It allows you to provide protection to your internal data and logic. Think about our dog example, everything was exposed as we saw from the main method itself. We could get access to all of the data and all of the methods. Encapsulation is a way to protect that. Data contained in structs can be protected from access outside the package itself in the same way methods on a struct can be protected. It's important to note that interfaces which we will talk about later, can have protected, or hidden methods, which is different than you see in interfaces in some other languages, specifically Java. Another benefit and one that goes along with protection is that encapsulation allows you to control the flow of data, both the setting…
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)
-