Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities

See the essence through the problem!!

Purpose of componentization:

Componentalization can clarify the responsibilities and boundaries of business modules, reduce the coupling between modules to reduce complex dependencies, improve code maintainability, improve the standardization and flexibility of business module scheduling, and further optimize the compilation speed.

So when do you want to componentize? As the complexity of project functionality increases, the business code is coupled more and more. This is where you can start thinking about componentization.

In layman’s terms, it’s like going to the convenience store near your dorm and walking right past it. There is no need to take a taxi, taxi efficiency is lower.

If you go to work (half an hour drive), you have to take a taxi or a bus. Walking is so slow that by the time you get there, it will be hours.

Componentization scheme

1. URL routing scheme;

2. Runtime reflection calls (simple reflection and secondary encapsulation target-action)

3. Target-action(category and dynamic scheduling);

4.

5. Notification scheme;

There are many kinds of componentized schemes, none of which is best, only which is the most appropriate. Common schemes are url-block, protocol-class, and target-action. So the reference of some articles on the Internet, the three schemes to do a simple contrast.

Url – block mushroom street

The routing center maintains a routing table in which the URL is key and the block is value.

Advantages:

1. Unify the differences between iOS and Android platforms

Disadvantages:

1. Url parameters are limited, only conventional string parameters can be transmitted, and data and image parameters cannot be transmitted;

2. Unable to distinguish between local and remote situations;

3. Components themselves depend on middleware, and there are many coupling of decentralized registration;

4, provide registration service at startup, save in memory.

protocol-class

Advantages:

1. Extended the function of local call;

2. Provide services by implementing interfaces with a wrapper layer in the middle;

3. Use protocol-class to create a mapping and save a mapping table in memory.

Disadvantages:

There is still the problem of maintaining the registry in memory

target-action

Using target-action mode to achieve decoupling between components, its function is completely independent, not dependent on middleware.

1, reflection through Runtime, direct call.

Generate the method signature and invoke method directly from the Invocation object.

3. Provide services to the outside world by wrapping a layer of wrapper around the component without incurring the original component code.

4. Middleware invokes component services through Runtime, and middleware catergory provides services to scheduler.

The consumer only needs to rely on the middleware, and the middleware does not need to rely on components.