Plug-in system [6] · programmer playing blocks

Source: Internet
Author: User

Since I started learning program design, I have been talking about object-oriented. When I first came into contact with C ++, I was really fascinated by its oo features. It is more colorful than the previously used C language. I thought that I was always proud to write a class for a long time.

Now I have been a programmer for some years. Looking back, I have learned some new ideas about oo.

I. objects outside the code

When talking about Oo, everyone will think of the class keyword. In the past, the teacher taught me this way. Although some languages have different performances, they are essentially similar. At the beginning, Oo was a technology. Later, Oo was a trend. Later, Oo was a belief. Later, Oo was an idea, in short, yuyue said Yuxuan.
However, it is certain that we can use oo ideas in languages that do not support oo features. For example, people who have learned C ++ to write C Programs may write c ++-style programs.

Further reasoning, oo ideas can be embodied outside of the language.

At the beginning of the year, we started to work on plug-in systems, so there are hundreds of plug-ins in the system. For such a system, the plug-in is equivalent to an object in a non-plug-in system. No one specifies that the object must be created by class. In previous articles, some comments from some friends said that this situation can be called "Object Model". This is what I mean here.

The plug-in is divided into two parts: code and configuration. The Code implements the plug-in business, and the configuration file processing plug-in features and the interaction between the plug-ins. It can be said that in the plug-in system, the code and configuration components can also be called "objects", that is, objects outside the code.

When we can get rid of the limitation of code, we can have a broader space for thinking.

2. Better Combination than inheritance

Encapsulation, inheritance, and polymorphism are three main characteristics of object-oriented. Encapsulation is good for plug-ins, but it is very difficult to implement inheritance and polymorphism. At least I have not seen anyone who has made the plug-in support inheritance.

In the past, someone asked me which of the three object-oriented features is the most interesting. At that time, my answer was polymorphism because it was the most flexible. Polymorphism is bound to inheritance. inheritance is strongly coupled. That is to say, the derived classes and the base classes cannot be decoupled. In some cases, inheritance and multi-State can bring unexpected benefits, but more often we need to replace inheritance with combinations to gain greater flexibility, especially at the system level.

For example, there are two modules with very similar functions. If we propose a base class based on the two modules based on the derived ideas, we inherit the two subclasses to complete the specific functions. There is no question about the objects in the code, but for objects outside the code, you can only use combinations to replace the idea of derivation. The practice is to make the public part of the two modules into a public sub-module C, different parts into A, B two modules. A and C are combined to generate the first module, and B and C are combined to generate the second module.
Another solution is to use configuration to process module features. You can refer to my previous articles.

In the design model, the emphasis is also placed on "combination is better than inheritance ".

Iii. Key Points of building blocks

Comparing software modules to building blocks means that our programmers are the people playing the building blocks. A variety of class libraries and frameworks, coupled with a variety of controls, are the building blocks we play. In the plug-in system, plug-ins are the building blocks. This article focuses on plug-in systems.

A good "Building Block" must have the following points:

1. pluggable and Dynamic Loading
2. Adjustable appearance
3. You can specify the display position.
4. Unified List Management
5. Communication between elements

Some basic points are introduced above, which are also several problems to be solved by the plug-in system. The above questions have been briefly introduced in previous articles. There are many ways to solve the above problems. Thanks to those who shared their solutions with me :)
In the current project, the most critical point is "configuration", which must meet the requirements, points 4 and 5 are essential factors for assembling plug-ins into a complete system.

4. What is technical content?

Programmers can be roughly divided into two types: building blocks and playing blocks.

The people who build blocks refer to those who write controls and plug-ins themselves. The people who play blocks refer to those who assemble various controls or plug-ins into a system. Most people in the industry recognize those who write their own controls, and they are dismissive to programmers who "only drag controls.

It is hard to say that the level of building blocks is high for people who are playing with building blocks, because they need two different capabilities. The leader must have a deep understanding of the underlying computer technology, while the leader must have a clear understanding of the business, user needs, and overall framework. People at both levels must be aware of optimization.

In the eyes of many students, the technical content refers to learning the underlying knowledge of the system and mastering the computer principles. However, after a period of time, especially for programmers who work in the industry, they may have different opinions, they are more concerned about how to "play with blocks. This is why the design model is rarely known among students, and basic theories such as algorithms are getting farther and farther away from professional programmers.

We cannot distinguish the technical content by building blocks or playing blocks. Different work focuses on different technologies. However, in my opinion, building blocks are what I really want to do, or architecture design. Of course, it is quite difficult to become a good architect.

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.