isAutoplayEnabled variable and method

Hey everyone!
First thanks for the great course!

Now the question

In the autoplay section we are creating a variable, and than a method to return the same value as the variable has. Please explai the logic of this solution. Is there any chance we can pass the value directly without creating a method?

Hi Nick,

Welcome to our community, and thank you for your question. :slight_smile:

Not passing on but you could make the variable public. This way, everything can access that variable and change its value. As you can probably imagine, making a variable accessible can lead to undesired issues, especially in larger projects.

To make our code more secure, we do not allow anything but the instance itself access the variable. Instead, we pass on the value of the variable.

Does that make sense?

Thanks Nina :slight_smile: )

Understood

You’re welcome. :slight_smile:


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms