Bas
Bas

Reputation: 23

What does encapsulation do for clearing up the type of a variable or constant?

I'm currently reading through Apple's "Intro to App Development with Swift" student guide. At the end-quiz of chapter 9, "Types", it asks:

When you're reading code and aren't sure of the type of a variable or constant, what's the quickest way to find out?

The answer is:

Rewrite the section of code using different encapsulation.

However, the concept of encapsulation has not been introduced before so I'm rather confused. In the e-book's Glossary, it states:

A language mechanism for restricting access to some of the object components and/or a language construct that facilitates the bundling of data with the methods of operating on that data.

Can anyone explain how this relates to finding out about the type of a variable or constant?

Thanks in advance.

Upvotes: 2

Views: 83

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726639

The answer is:

Rewrite the section of code using different encapsulation.

That's a wrong answer. The right answer is "Use Xcode's [Quick Help] inspector."

Can anyone explain how this relates to finding out about the type of a variable or constant?

The suggestion here is that if you rewrite the source to make a private variable public (i.e. change the way it is encapsulated) it would make it easier to find the type of the variable in question.

Upvotes: 1

Related Questions