Deep understanding of plug-in systems

Source: Internet
Author: User
Brief

To develop a successful system, Plug-ins are a must. For the children, the building blocks are wood plastic, with these small blocks can be spelled into houses, animals. For construction workers, building blocks are 0 bricks and tiles, which can be used to build tall buildings. For programmers, building blocks can be seen as plug-ins (a bit more advanced), with these small blocks to build large systems.

Many people think that plug-ins are very complicated, and they shut them out. In fact, from the perspective of the use of the framework, it is quite simple. The hardest part is not in the framework itself, but in changing the existing development model. There is a habit called "rut", yes, yes ... For the program Ape/yuan, in this state, and coding machine what is the difference.

A brief description of why Plug-ins are introduced to plug-in plug-ins the principle of plug-in framework elements

Copyright: A go, two or three, reprint please specify the Source: http://blog.csdn.net/liang19890820 Why to introduce Plug-ins

In the software development process, there is a very challenging task: build to meet the future needs of customers products.

In particular, software into the expansion/maintenance phase, but also so. However, at this stage, there are often a lot of bad situations: software design is unreasonable without the corresponding document team members leaving (or transferred to other project teams) ...

At this point, if a new developer is involved in the product improvement, then congratulations. Not only do you feel particularly laborious when extending functionality, but there is also the risk of damaging existing functionality. Of course, if you can find a start-up team member to assist, then it will be very happy ...

In addition, the development cost of adding new features to existing products is very high. Because the entire system needs to be tested again and released as another version.

To solve these problems, plug-ins appear. What is a plugin

Excerpt from Wikipedia:

A plug-in (Plugin) is a computer program that interacts with applications (such as Web browsers, e-mail clients) to add some of the specific functionality required for an application. The most common plugins are games, web browser Plug-ins, and media players. the mission of the plug-in

Plug-ins are usually deployed as dynamic libraries, dynamic libraries give plug-ins a number of advantages: hot-swappable (reloading new implementations without shutting down the system) separating the source code from the application facilitates the internal developer to add functionality that allows Third-party developers to securely extend the application (additional functionality without modifying the core system)

However, sometimes the static library is the best choice for Plug-ins: For some systems that do not support dynamic libraries (many embedded systems) are not allowed to load external code because of security problems the core system needs to preload some plug-ins and statically link them to executable programs (prevent users from accidentally deleting them)

Of course, a good plug-in system should both support dynamic plug-ins, but also support static plug-ins. In this way, you can deploy the same set of plug-in systems in different environments with different constraints. the principle of the plug-in

Principle: interface-oriented programming, not object-oriented programming.

Plug-ins are all about interfaces, a plug-in based system, the basic concept is that the system can load plug-ins, but it does not know anything, and through a set of well-defined interfaces and protocols to communicate with them.

This can be seen in the use of plug-ins to extend QT applications:

Class IPerson
{public
:
    virtual ~iperson () {}
    Virtual QString name () = 0;  Man has name
    virtual void eat () = 0;  People need to eat.
    virtual void sleep () = 0;  People need to sleep.
    virtual void dosomething () = 0;  People also need to do other things
};

The goal of the plug-in is to implement IPerson, the business layer's goal is to call the IPerson, the business layer does not know how to achieve IPerson specific, and the implementation does not need to care how the business layer is called. elements of the plug-in framework

To implement a plug-in framework, you need to consider the following elements:

How to register a plug-in

How to invoke a plug-in

How to test a plug-in
Framework to support automated testing: Includes unit tests, integration tests.

Life cycle Management for Plug-ins
The lifecycle of the plug-in is controlled by the plug-in framework, and the following issues need to be considered: how the plug-in lifecycle is converted. Once the life cycle of the plug-in changes, whether the class referencing the plug-in can be notified.

Management and maintenance of Plug-ins
This is the basic functionality for the plug-in framework. Mainly include: For Plug-ins to provide the name, version, status and other information, and can obtain a list of plug-ins, recording plug-ins processing logs. Provide plug-ins to load, start, stop, uninstall and other functions.

Assembly of Plug-ins (additional evaluation elements)
Plug-in assembly refers to the flexibility to assemble multiple plug-ins into a chain, and then chained to the call.

Error handling of Plug-ins
When the plug-in in the process of error, the ideal result is the call to stop the plug-in, and log the relevant logs, the other plug-ins to do error correction ( Note: the plug-in framework and other plug-ins can not affect the normal operation).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.