What is monkey patching?

前端 未结 8 2032
[愿得一人]
[愿得一人] 2020-11-21 16:35

I am trying to understand, what is monkey patching or a monkey patch?

Is that something like methods/operators overloading or delegating?

Does it have anyt

8条回答
  •  感情败类
    2020-11-21 17:16

    Monkey patching can only be done in dynamic languages, of which python is a good example. Changing a method at runtime instead of updating the object definition is one example;similarly, adding attributes (whether methods or variables) at runtime is considered monkey patching. These are often done when working with modules you don't have the source for, such that the object definitions can't be easily changed.

    This is considered bad because it means that an object's definition does not completely or accurately describe how it actually behaves.

提交回复
热议问题