Classes and Encapsulation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Classes and Encapsulation

Hey, I'm currectly learning about "encapsulation". I got its concept, but it's very confusing to me, when the explaination uses the terms "class" and "object" in one context. For example: Quote: "it also means restricting access to the inner workings of that class." I think they mean "object" instead of class, since a class is only a blueprint and the object is the entity, you can actually access. Why do they use the term class then? Another question: They explained the advantage of encapsulation: Quote: "- Code is more flexible and easy to change with new requirements. - Change one part of code without affecting other part of code." What do they mean by this? Could you show me an example please? Thanks in advance

7th Dec 2018, 4:29 PM
Dominik Wolf
Dominik Wolf - avatar
2 Answers
+ 1
Because they mean all objects of the class not a particular one, they use class. The best example I can think of is location addresses. Today, you might keep the actual string. Tomorrow, you might use a data structure provided by Google Maps. The getter/setter could stay with the string so the other code outside the class won't change. But, the internals of storage and usage would change.
7th Dec 2018, 5:10 PM
John Wells
John Wells - avatar
7th Dec 2018, 8:59 PM
Sebastian Keßler
Sebastian Keßler - avatar