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
2 Respostas
+ 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.
0
Maybe this Code can help you:
https://code.sololearn.com/cvv4UqkEtPDH/?ref=app