BackgroundWindows Qianniu has a lot of functions. When will Mac Qianniu be able to align their capabilities?I believe that all cross-platform applications have encountered such a dilemma. Due to the complexity of platform differences, the cost of maintaining multi-terminal products is very high, and there are often problems with inconsistent multi-terminal experiences. This is the case, and our team maintains two cross-terminal products, PC Qianniu and PC Wangwang. Under the dual pressure of performance and experience, it is imperative to build a unified multi-terminal PC application cross-platform development framework. This article mainly introduces our thoughts on the componentization part, solution selection, some problems encountered and solutions in the Qianniu PC cross-terminal framework. The so-called framework is both a "frame" with certain constraints and a "frame" with certain support. In the IT context, the framework specifically refers to a support structure with certain constraints designed to solve an open problem. More components can be expanded and inserted on this structure according to specific problems, so as to build a complete solution to the problem more quickly and conveniently. Why do we need componentization?Why do cross-end frameworks choose to be componentized?The framework itself generally cannot directly solve a specific problem, but it provides some basic capabilities for connecting and combining related components to solve the problem. The scientific nature and ease of use of the framework directly determine R&D efficiency and product quality. Componentization is a very suitable technical solution to solve the expansion and reuse of framework functions. An application framework designed using the componentization model generally has the following characteristics:
Each of these advantages is what we dream of, so componentization is almost an inevitable choice for us. What is componentization?Componentization refers to the process of splitting and reorganizing multiple functional modules when decoupling complex systems, with various attributes and states reflecting their internal characteristics. For example, you want to build a car, but find that the car is too complicated and difficult to realize, so:
A functional module here is a component, and the system used to control the collaborative operation of components is the component framework. Several issues that the component framework needs to solve:
How to choose a componentized solution?There are many component-based implementation solutions. How do we choose the technical solution that suits us?There are many componentization solutions in the industry, such as com components under Windows, ARouter components under Android, ths components based on message bus, prg::com components developed by Qianniu, and some components based on RPC framework in a broader sense (microservices). In my opinion, there is no best componentized solution, only a relatively suitable one. According to the business scenario, you can choose a solution that meets the current business needs, takes into account the future development needs, and is easy to use and maintain. Here are some dimensions for reference when selecting component solutions:
In the cross-end Qianniu scenario, our priority is:
Here we mainly compare the ths component and the prg::com component solution:
Finally, we chose our self-developed prg::com as the technical solution for cross-end framework componentization. The following is a detailed introduction to this solution. Cross-end componentization practiceThe componentized solution includes two parts: framework capabilities and component constraints. Whether the framework design is scientific and whether it is easy to develop, use, and maintain under component constraints are the core factors to be considered in component-based solutions.
Component constraints are defined based on factors such as component type and specific usage scenarios, and the standards for different components are not exactly the same. For example, the standards for UI components and non-UI components are very different. The following is an introduction to the prg framework and the component constraints we define in various scenarios. ▐ prg framework
The prg framework uses template technology to scan dlls to generate configurations during packaging and statically register components when loading dlls, thus implementing a component discovery mechanism. The component discovery mechanism of the prg framework relies on id registration. The components only expose class ids and I interfaces to the outside world, thus achieving complete de-dependency between components. Let's take a look at the schematic code first: // Define a prg::com component Its implementation principle is:
C++ template technology and static registration technology are used here to cleverly decouple components and solve dependency problems and cross-module calling problems.
The prg component supports seamless cross-module creation, use, and release of objects, truly achieving one-time development and use everywhere, ready to use out of the box. The prg component uses scoped_refptr reference counting to manage memory, and users do not need to manage memory themselves. The prg framework supports the creation, use, and release of objects across dll/dylib. For users, dll/dylib is completely invisible. You only need to specify the object type, interface type, and instance name to be created, and then you can start using this interface directly, which is very smooth. class IxxxService : public prg :: IPrgCOMRefCounted We usually encapsulate component acquisition into an interface like the following. For users, calling the interface is as convenient as calling their own code. /// Component header file
Interface calling and event subscription of prg component. Interface call The interface call of prg component is similar to that of com component, the difference is that prg::com has a better encapsulation, which can directly get the I interface object for use. (Of course, it still supports the use of QueryInterface, and different types of I interfaces can be obtained through QueryInterface) class IxxxService : public prg :: IPrgCOMRefCounted Event Subscription Event subscription and dispatch, which is implemented by base::event, is a typical observer mode. When an event is triggered, the observer's base::callback is called one by one in the order of registration, which can easily complete complex process series connection. The event here is at the instance level, and with the account isolation capability of prg, it can solve the event dispatch problem of multi-account business. However, base::event does not currently support registration and dispatch by priority. class IxxxService : public prg :: IPrgCOMRefCounted ▐ Component constraints of the prg frameworkWhat constraints must prg::com components follow? Different types of components have different standards. To talk about component standards, we must first classify the components. Taking the Aliwangwang application as an example, the components included in the cross-terminal Wangwang can be roughly divided into the following categories: Framework layer:
The framework and basic components are the base of Alibaba's PC applications. These components are built into the prg framework, thus enabling the ability to quickly build cross-terminal PC applications. Application layer:
Application layer components are mainly used to implement business functions. These components often need to be expanded and modified, and are what we should focus on. Application layer components can be divided into UI-related and UI-independent components according to their technical implementation. UI components are relatively more complex. (ps: The UI components use pv layering. The p layer is responsible for controlling the interface logic and is implemented in pure C++. The view layer is only responsible for drawing and input operations. This maximizes code reuse, improves efficiency, and ensures consistency between the two ends of the business. Our UI components all comply with this standard. We chose Qt as the cross-end UI framework. We found that Qt cannot achieve full cross-end UI functions. Considering the possibility of replacing the UI framework or adapting to new platforms in the future, we limit the use of Qt to the UI rendering part, that is, the view layer.) prg component general standard prg::com component base standard, all prg components comply with it. Each prg component is named...Service, exposed to the outside world in the form of I...Service interface, and implemented in C...Service. Service concept: Service is a prgcom component, an independent business unit within the client, and an abstraction of independent business capabilities. Interface: IxxxService (in the biz/interface directory, IxxxService.h file) Implementation: CxxxService (in the biz/xxx/service directory) Get instance: GetxxxService() Directions:
Non-UI component standards Components that do not include UI interfaces are less affected by platform differences. They are designed internally according to business needs and comply with the basic standards of PRG components.
The standards for cross-end UI components mainly include MVP layering, UI lifecycle management, and multi-UI combinations in various scenarios. The UI component still complies with the general standards of the PRG component and supports all the features of the PRG component. Service: It is a prgcom component object. When using UI components externally, you can directly operate the service, just like using non-UI components . UI: It is the overall interface. UI includes presenter and view. UI and view should be clearly distinguished here. Presenter: It is the logical object of the interface. The p layer controls all business logic and also controls the input and output of the view . View: It is the rendering object of the interface and is only responsible for interface rendering and user operation input . In the prg framework, component A calls the UI interface of component B: Complexity of UI components:
MVP hierarchical structure In order to better maintain and reuse UI components and meet cross-end demands, our UI components are developed using the MVP model. In addition to complying with prgcom standards, UI components must also comply with additional constraints:
The main benefits of this design are:
Lifecycle Management The life cycle of UI components is more complicated than that of general components because the life cycle of some objects of UI components is managed by the UI framework. Buy Wang cross-end framework, the ui selection is Qt framework, the ui object life cycle is managed by the Qt kernel, and the component life cycle is managed by the prg kernel. After the UI object is created, the component saves the pointer to the UI object in order to interact with the UI object, but the life cycle of the UI object is managed internally by Qt. Therefore, we need to establish a mechanism so that when Qt destroys the UI object, our component will be notified that the UI object has been destroyed. Create and call a process: Destruction process: Processing of various UI interfaces Single UI interface Multiple flat UI interfaces Parent-child UI interface Interface calls under multi-layer UI interface nesting Since there are too many nested levels, each level needs to open an interface for transmission, which will bring a lot of workload, so a generalized interface transmission solution is provided. You can refer to the implementation of the IAliwangwangChatBase.h case to complete the interface transfer. Automatically generate component code Cross-platform, standardization, and low coupling often mean more complicated coding and difficulty in implementation. For example, if I want to operate component B in component A and display a dialog box, the code I need to write is:
Writing code in 6 objects is simply a disaster!!! But considering long-term maintainability and cross-platform, it must be done this way. Therefore, we developed a code generation tool that can automatically generate component code from templates based on the UI relationships in the above situations. Due to space limitations, this will not be discussed in detail here. ▐The effectThis cross-end componentized solution has been implemented in the cross-end Qianniu/cross-end WantWant products, and currently two products and three ends have been released and launched. (Currently, the function of win Qianniu is greater than cross-terminal Qianniu. The win version of cross-terminal Qianniu has not yet been released, so stay tuned)
Let’s go back to our goal when we chose this solution.
At present, the prg component framework performs well in the first three points. In terms of the fourth point, the R&D experience, due to the stringent requirements across multiple terminals, the UI components have many layers and the development is a bit cumbersome. We have alleviated this problem through self-developed component code generation tools. In general, the prg component cross-end framework can well support the business of Qianniu/Wangwang and even other Alibaba PC applications in the next 3-5 years. Thinking about the evolution of cross-end component framework▐Improvement of technical basic capabilitiesFramework basic capabilities, such as supporting event subscription priority, supporting component link/performance monitoring, and adding basic capability components. UI component unit testing capability. UI components are all pv structures, and UI logic is all in the p layer. You can use a simple uidelegate to connect UI logic in series to implement UI unit testing. Improve R&D efficiency and experience, improve code templates and automation tools, realize automatic generation/completion of interface-level code, and further improve R&D efficiency and experience. ▐Possible business attemptsTowards business componentizationComponentization is not only a technical concept, but also a business concept. Reuse brings low cost and consistency, while decoupling brings business flexibility. Flexible reuse of components in technology can bring about flexible business combinations and rapid trials. For example, the IM capability of Wangwang can be an independent Ali Wangwang product or integrated into Qianniu. Components are building blocks. If we think more from a business perspective and provide more and better building blocks, the business can quickly build a new building.
Componentization is not limited to the team. The PC business component library shared and built by everyone can maximize the value of componentization. I hope the PC business will get better and better! About the Team We are the cross-terminal technology team of the industry and merchant technology department of Taobao Technology. We are responsible for creating the most efficient one-stop workbench Qianniu for tens of millions of merchants, and providing stable and efficient end-to-end message IM services for hundreds of millions of merchants and consumers on Taobao. Technically, we are deeply engaged in C++ cross-terminal and PC desktop technology (Windows & Mac), providing merchants and consumers with stable, reliable and efficient client products. |
<<: iOS 15.6 official version battery life test is out, it consumes more power
>>: How big is the difference between iOS 15.4.1 and iOS 15.6? Is it worth upgrading?
We will find that most of the traffic comes throu...
There are many sub-sectors of Internet finance pr...
Expert of this article: Li Siwei, Secretary Gener...
Since Apple launched AirPods, wireless earphones ...
Editor’s Note: After the comprehensive science ex...
Some time ago, a friend asked me on WeChat, if I ...
During the development process, you may encounter...
On December 8, CCTV News officially settled in Bi...
Plants convert carbon dioxide into roots, stems, ...
Recently, a list of the death of smart hardware w...
Tag (called "label" in Chinese) is a ne...
I have the model in hand and the idea. If you don...
Entering 2018, major companies have begun to form...
The annual settlement of personal income tax for ...
Zheng Xiangzhou Business model + capital operatio...