Use Methods Change State Turtle Object Instead Directly Changing Values Attributes Q37236585

Why do we use methods to change the state of a Turtle objectinstead of directly changing the values of its attributes?


Answer


That’s one of the pillars of the object-oriented programming. Wegive methods/functions to the outside world/user and ask them toinvoke the methods to change any of the attributes. We don’t wantto expose the inner details of the class like how the values arestored(in sense like data type and so).

Generally, we have the data attributes as private as no otheruser/class can access them and we have methods to change theseattributes. Methods are like the black-box of the class. We justprovide

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.