In the era of soft generation, there was already a magic weapon to solve this problem (all bugs are eliminated) - componentization. Of course, it was not called that at that time. This issue was regulated through two principles: cohesion and coupling (high cohesion, low coupling).
Coupling: Also known as inter-block connection. It refers to a measure of the closeness of interconnection between modules in a software system structure. The closer the connection between modules, the stronger the coupling, and the worse the independence of the module. The level of coupling between modules depends on the complexity of the interface between modules, the calling method and the information transferred (recommended learning: PHP video tutorial)
Cohesion: Also known as intra-block contact. It refers to the measure of the functional strength of a module, that is, the measure of how closely the elements within a module are combined with each other. The more closely the elements (between language names and program segments) within a module are connected, the higher its cohesion will be.
Component-based development is the standardization work of encapsulating certain functions that can be reused. Components generally contain their internal UI elements, styles and JS logic code, which can be easily and quickly embedded anywhere in the application. Components can use other components inside to form more complex components. Component development is a useful solution.
Definition of componentization
Understand "componentization" as the following elements:
a) A component is an encapsulation of logic and is not limited to graphic elements.
That is, we can make if into a component, a countdown into a component, an animation into a component, routing into a component, and data architecture into a component, but these cannot be called The control
b) component has a single portability
that is, "ready to use as soon as it is loaded". There is no need to prepare complex basic conditions for it (such as introducing styles, Introducing frameworks, etc.). However, the existing so-called component libraries do not do this well, and it is not technically realistic
c) Components are defined declaratively, not imperatively.
I don’t want to say more about this. It’s largely my own subjective idea. The most important thing above is the first point, so if you ask me what “component-based development” is, my answer is : A development model that abstracts various graphical and non-graphical logics into a unified concept (component).
The biggest difference between this and the traditional development framework is the unification of graphical elements and non-graphical elements. Apart from this, I can't think of any other points that really reflect the difference. Under this concept, including router, ajax, Module loader, timer, animation, interval, etc. are all components, sharing unified life cycle management and external interfaces, and are combined declaratively.
Strongly advocate the benefits of component development method
Greatly improve the project compilation speed
After component splitting , each business or function is a separate project. This separate project can be compiled and run independently. The split projects are usually smaller and have less code. I no longer have to wait for several minutes to compile as before. .
Decoupling of business modules is conducive to collaborative development of multi-person teams
Business components cannot refer to each other, and each component converges the corresponding business functions into one In the project, they don’t disturb each other. In a multi-person team, each person is only responsible for his own business module. His additions, deletions, modifications and checks of business functions are limited to his own business module and will not affect other people's business. The quality of his code will not be affected. It will only affect your own business modules; it is also very convenient for testing. In most cases, we only need to focus on testing the modified business components instead of always performing all regression tests.
Componentization is the cornerstone of functional reuse
Business components are like building blocks. We can use building blocks to build different houses. In the same way, we can also create multiple A different APP. We only need to maintain each component. When we need to use the function of the component, we can just create a reference and integrate it.
For more PHP related technical articles, please visit the PHP Graphic Tutorial column to learn!
The above is the detailed content of What is component development. For more information, please follow other related articles on the PHP Chinese website!