当前位置:网站首页>What is modularity? Benefits of modularity

What is modularity? Benefits of modularity

2022-06-12 12:04:00 Mustang (Mustang)

What is modularity

In short , Modularization is to divide a large file into independent and interdependent small modules in an organized way .
There are many private properties inside the module , Only a part of the exposed interface is exposed ( For example, you can modify the methods of private attributes )
Modularity is a way to deal with the decomposition of complex systems into better manageable modules .
The so-called modular development is packaging details , Provide and use interfaces , Don't affect each other , Each module implements a specific function . The foundation of modular development is function . Modular development reduces code coupling , The significance of modularity is to maximize design reuse , With the least number of modules 、 Spare parts , More quickly meet more personalized needs .
The benefits of modularity
ES6 Before ,JavaScript The language has never had a module (module) system , Large files cannot be organized into small pieces , And manage dependencies between . But the idea of modularity has always existed . Because with Javascript The code is getting bigger and bigger , And web pages are more and more like desktops APP. Such a jumble of code , If not modularized , May cause naming conflicts , Not easy to reuse 、 High maintenance .

The benefits of using modular development

1. High cohesion and low coupling , It is conducive to team operation , When the project is complex , Divide the project into sub modules and assign them to different people for development , Finally, put it together , This can reduce the dependency between modules and reflect low coupling , The module has specific functions to reflect high cohesion .

2. reusable , Convenient maintenance , The characteristic of the module is that it has specific functions , When both projects need some functionality , We define a specific module to implement this function , In this way, you only need to introduce this module in both projects to realize this function , No need to write repetitive code ; And when the requirements change and the function needs to be changed , We modify this module directly , In this way, you can modify the functions of all projects , It's easy to maintain .
3、 adopt exports Expose interfaces . This means that no namespace is needed , Not to mention global variables . This is a complete naming conflict solution .
4、 adopt require Introduce dependencies .** This allows dependencies to be built in , Developers only need to care about the dependency of current modules , Other things Sea.js/ Require.js They'll handle it automatically

原网站

版权声明
本文为[Mustang (Mustang)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121158415363.html