Greetings!
Given:
-
An existing class with various attributes and characteristics.
- Example: the “easygopygo3” class defined within the easygopigo3 library.
- Example: the “easygopygo3” class defined within the easygopigo3 library.
-
Assume that, for whatever reason, certain characteristics are undesirable or need to be modified for the duration of the project, such that the modification becomes “intrinsic” and sticky.
- Example: The default speed is “300”, but you may wish to change it to “500” or “200” or whatever - and have the value stick. As @cyclicalobsessive discovered, resetting the value is not sufficient as it gets periodically reset to the original value of “300”. Or, you’d rather have the value of “mutex” equal to “true” instead of “false”.
- Example: The default speed is “300”, but you may wish to change it to “500” or “200” or whatever - and have the value stick. As @cyclicalobsessive discovered, resetting the value is not sufficient as it gets periodically reset to the original value of “300”. Or, you’d rather have the value of “mutex” equal to “true” instead of “false”.
-
(Advanced topic)
Perhaps a method does something that doesn’t make sense, (speed or the way something turns is implemented THIS way, but you’d rather have it THAT way instead.- Example: You want to prevent the motors from being damaged, or the servo’s you are using need different pulse characteristics, or whatever other reason you might have.
Question:
What is the best way to “overload”, (I believe that’s the correct term), some aspect of a pre-existing class when instantiated, (i.e. gopigo3_robot = EasyGoPiGo3()
)?
Thanks!
P.S.
I am assuming this is the correct way to “temporarily” change something - that is within the scope of a particular project or program.
I am also assuming that if you need the change to be more permanent, you would actually modify the code within the library itself, and then rename it to something unique like my_easygopigo3. (or, perhaps create a new class definition within the library with a different name and your unique changes as an overload to the base class?)