当前位置:网站首页>Hooks' design philosophy

Hooks' design philosophy

2022-06-11 01:21:00 zhen12321

hooks The word "hook" means "hook" . There is such a word in many frameworks . It is essentially a Callback function .
Why do you call him a hook ? Is it just for the convenience of understanding ?
It's not like that .
The main purpose of the word hook is to indicate a set of operations at a specific time in the software life cycle .
Software engineering is a very large and complex subject , It is the methodology of software development .
The general execution process of a software is divided into some specific time , for example : Before the object is created , After creation , Before some instances of the object are called , After being invoked .
hooks It is a concentrated embodiment of the programming mode of functional programming , It describes the principle that software is invoked according to time .
however , I think functional programming is a variation of class programming , Their essence is to enhance the operation of components . However, the feature of functional programming makes it necessary to add some functions only in certain areas chain To insert in the middle of , But in the class, we can enhance the method without any scruple .
Just like functional programming is more flexible than object-oriented , So there are fewer things to consider .
So we can expose some callback functions at a specific time , Make some enhancements in these callback functions .
Compare face objects AOP For the design idea of , This obviously adds some enhancements to the original code . Is actually inserted into the code some new Code for .
In a classic software framework , The advantages of this design idea can be magnified infinitely .
for example , In one use C++ Written in a classic framework that won't change much , Everything is very stable .
If the hooks This way to interfere , To enhance a corresponding software design , So back to this excellent and stable framework , You can really enhance the design idea of such a software .
The key is not to pollute the software . Although in series , But I can be pluggable . This is the most magical place .
This line of thinking , It's also webpack,react17 An important train of thought and thought in .
Let's return programming to functions , Remove the heavy runtime of face objects .

原网站

版权声明
本文为[zhen12321]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110015559077.html