"Encapsulation is used to hide the values or state of a structured data object inside a class, preventing unauthorized parties' direct access to them."
You're basing your argument on the wrong premises:
It's a common misconception that encapsulation is about "hiding" something. It isn't.
Yes, encapsulation is - among other things - used to prevent direct access to a property or method, but this has nothing to do with "authorization" (another common misconception).
The whole idea here is to hide the details in a class so they cannot be changed outside class. It is obvious that using the approach I propose, they cannot be changed outside the class, however,@joelnet
, outlined means that they can be accessed outside the class and then modified, which refutes the article.
I'm sorry this will seem like nitpicking, but I believe concepts are truly important: every property, unless static (which I don't believe JS has, but I might be wrong), is always being accessed "outside the class", since they are being accessed in an object, and not the class itself.
My goal is not the final result you wish (protecting the properties), but just to set OO straight.
Sammy Israwi is absolutely correct: the way to do it in OO is through what we call visibility (setting a property or method as public, protected or private), which seems to be in ES' future.
"Encapsulation is used to hide the values or state of a structured data object inside a class, preventing unauthorized parties' direct access to them."
You're basing your argument on the wrong premises:
Yes, encapsulation is - among other things - used to prevent direct access to a property or method, but this has nothing to do with "authorization" (another common misconception).
The whole idea here is to hide the details in a class so they cannot be changed outside class. It is obvious that using the approach I propose, they cannot be changed outside the class, however,@joelnet , outlined means that they can be accessed outside the class and then modified, which refutes the article.
Thanks for the feedback too.
I'm sorry this will seem like nitpicking, but I believe concepts are truly important: every property, unless static (which I don't believe JS has, but I might be wrong), is always being accessed "outside the class", since they are being accessed in an object, and not the class itself.
My goal is not the final result you wish (protecting the properties), but just to set OO straight.
Sammy Israwi is absolutely correct: the way to do it in OO is through what we call visibility (setting a property or method as public, protected or private), which seems to be in ES' future.
No worries. I appreciate the way, we are tackling the flaws though. That is a good way of critiquing an article.