Factory a mechanism to enforce encapsulation #60
Unanswered
OpenTechConsult
asked this question in
Q&A
Replies: 1 comment
-
The function createPerson(name) returns an object with 2 methods: setName(name) and getName(). There isn't any other possibility of changing or accessing the value of privateProperties other that using that two methods. Those methods can access the privateProperties because a closure captures the context, and that context includes privateProperties. And the access to the value of privateProperties is encapsulated in the person object. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I reached chapter 7 of the book. I am on the section Factory:: A mechanism to enforce encapsulation. I can't understand how closure and scope enforce encapsulation. I can't understand the encapsulation in the given code snippet as an illustration
Beta Was this translation helpful? Give feedback.
All reactions