Low-coupling software architecture method and apparatus based on multi-modal components and message hooks
By employing a loosely coupled software architecture approach using multimodal components and message hooks, the problem of tight coupling in inter-module communication is solved, achieving complete decoupling and flexible bidirectional communication between modules. This improves the maintainability and scalability of the software and supports independent development and hot updates of modules.
Patent Information
- Application Number
- CN202611022150.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-09
- Publication Date
- 2026-11-24
AI Technical Summary
Existing software architectures exhibit tight coupling between modules, making it difficult to achieve elegant bidirectional communication. This results in insufficient system flexibility and scalability, especially in scenarios requiring bidirectional interaction, which can easily lead to circular dependencies or implicit temporal dependencies, making independent development, testing, and hot updates difficult.
We adopt a loosely coupled software architecture approach using multimodal components and message hooks. By encapsulating business data and subsequent logic into hook messages, we use a message bus for routing and call hook functions to execute subsequent logic after the receiver has finished processing. We also combine a dynamic module manager and weak reference tokens to manage the module lifecycle.
It achieves complete decoupling between modules, improves team collaboration efficiency and software maintainability in large projects, simplifies debugging and expansion of complex business processes, supports independent development and hot updates of modules, and enhances the flexibility and reliability of the system.
Smart Images

Figure CN123157282A_ABST
Abstract
Description
Technical Field
[0001] The embodiments in this specification relate to the field of computer software technology, and in particular to a loosely coupled software architecture method based on multimodal components and message hooks. Background Technology
[0002] Current software architectures, when building complex systems, typically employ object-oriented design or entity component systems. Modules communicate by directly calling each other's interfaces. This strong dependency means that modules must know each other's definitions at compile time, leading to tight coupling. To address this issue, message-driven or event-driven frameworks are widely used, allowing objects to communicate decoupledly via signals, slots, or event buses. However, these mechanisms primarily support one-way notifications. When the receiver needs to process and provide feedback to the sender or perform subsequent operations, independent callback messages, complex state listeners, or additional callback mechanisms must be introduced. This results in business logic being fragmented across multiple locations, reducing code readability and maintainability. In entity component system architectures, inter-system collaboration often relies on adding temporary tagged components to entities or using a global event bus. The former compromises the purity of components, causing entities to carry excessive temporary data, while the latter can lead to chaotic event management and debugging difficulties. Existing solutions struggle to achieve elegant bidirectional communication while maintaining complete decoupling of modules. Deep-seated dependencies between modules are difficult to eliminate completely, especially in scenarios requiring bidirectional interaction, which can easily lead to circular or implicit temporal dependencies. This makes it difficult for the system to be developed, tested, and hot-updated independently, resulting in insufficient flexibility and scalability of the architecture.
[0003] Therefore, a better solution is urgently needed. Summary of the Invention
[0004] In view of this, embodiments of this specification provide a loosely coupled software architecture method based on multimodal components and message hooks. One or more embodiments of this specification also relate to a loosely coupled software architecture apparatus based on multimodal components and message hooks, a computing device, a computer-readable storage medium, and a computer program, to address the technical deficiencies existing in the prior art.
[0005] According to a first aspect of the embodiments of this specification, a loosely coupled software architecture method based on multimodal components and message hooks is provided, comprising: The sender encapsulates business data and subsequent logic into hook messages, which contain business data and hook functions for callbacks. The hook message is sent to the message bus, which routes the hook message to the receiver registered to handle that type of business data based on the type of business data. The receiver extracts and processes business data from the received hook messages; After processing is complete, the receiver calls the hook function in the hook message to execute subsequent logic in the sender's context.
[0006] One possible implementation also includes a step of managing the module's lifecycle through a dynamic module manager, specifically including: Load or unload the sender or receiver using the dynamic module manager; During initialization, the module registers the message types it can handle with the message bus; Associate a weak reference token with the hook function. The weak reference token is used to characterize the lifecycle state of the sender that provides the hook function.
[0007] In one possible implementation, a validity check of the weak reference token is included before the receiver calls the hook function: If the weak reference token is valid, the hook function is allowed to be executed; If the weak reference token is invalid, the hook function call is safely discarded.
[0008] In one possible implementation, the method is applied in an entity component system architecture, where the sender and receiver are systems within the entity component system architecture.
[0009] In one possible implementation, within an entity component system architecture, the steps for workflow orchestration between systems via messages carrying hook functions include: After processing the entity, the first system generates a first hook message carrying a first hook function and sends the first hook message to the second system. After the second system processes the first hook message, it calls the first hook function, which contains the second hook message to be sent to the third system.
[0010] In one possible implementation, the hook message is a template class that includes at least a sender identifier field, a business data field, and a hook function field.
[0011] One possible implementation also includes invalidating all weak reference tokens associated with a module when the dynamic module manager unloads the module.
[0012] According to a second aspect of the embodiments of this specification, a loosely coupled software architecture apparatus based on multimodal components and message hooks is provided, comprising: The data encapsulation module is configured so that the sender encapsulates business data and subsequent logic into hook messages, which contain business data and hook functions for callbacks. The data sending module is configured to send hook messages to the message bus, and the message bus routes the hook messages to the receivers registered to process that type of business data according to the type of business data. The data extraction module is configured to allow the receiver to extract and process business data from the received hook messages. The logic execution module is configured so that, after processing is complete, the receiver calls the hook function in the hook message to execute subsequent logic in the sender's context.
[0013] According to a third aspect of the embodiments of this specification, a computing device is provided, comprising: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, they implement the steps of the above-described low-coupling software architecture method based on multimodal components and message hooks.
[0014] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided that stores computer-executable instructions, which, when executed by a processor, implement the steps of the above-described loosely coupled software architecture method based on multimodal components and message hooks.
[0015] According to a fifth aspect of the embodiments of this specification, a computer program is provided, wherein when the computer program is executed in a computer, it causes the computer to perform the steps of the above-described method for a loosely coupled software architecture based on multimodal components and message hooks.
[0016] One embodiment of this specification encapsulates business data and subsequent logic into hook messages containing hook functions, which are then routed to the receiver via a message bus. This allows the receiver to directly call the hook function after processing the business data to execute subsequent logic within the sender's context. This merges the traditionally separate requests and callbacks into a single, self-contained communication unit, fundamentally changing the mode of bidirectional interaction between modules. The sender does not need to define additional callback interfaces or listen for events, and the receiver does not need to know any details about the sender; it only needs to call the hook function after processing the core business logic. This enables modules to interact solely through message contracts, completely eliminating direct dependencies at compile time and runtime. Each module can be developed, compiled, tested, and deployed independently, significantly improving team collaboration efficiency and software maintainability in large projects. All inter-module interactions, including forward requests and reverse callbacks, are encapsulated in hook messages, making data flow and control flow explicitly visible at the architecture level. This greatly facilitates visual debugging, performance profiling, and system behavior analysis. Complex business processes are decomposed into a series of atomic operations linked together by hooks, separating the control logic of macro-business processes from the internal implementation of modules, making them more declarative, configurable, and easy to trace and debug. Attached Figure Description
[0017] Figure 1This is a flowchart illustrating a loosely coupled software architecture method based on multimodal components and message hooks, as provided in one embodiment of this specification. Figure 2 This is a system schematic diagram of a loosely coupled software architecture method based on multimodal components and message hooks provided in one embodiment of this specification; Figure 3 This is a schematic diagram of a loosely coupled software architecture device based on multimodal components and message hooks, provided in one embodiment of this specification. Figure 4 This is a structural block diagram of a computing device provided in one embodiment of this specification. Detailed Implementation
[0018] Many specific details are set forth in the following description to provide a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this specification. Therefore, this specification is not limited to the specific implementations disclosed below.
[0019] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the one or more embodiments of this specification. The singular forms “a” and “the” as used in one or more embodiments of this specification and the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0020] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this specification, and similarly, second may also be referred to as first. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to a determination."
[0021] This specification provides a method for a loosely coupled software architecture based on multimodal components and message hooks. This specification also relates to an apparatus for a loosely coupled software architecture based on multimodal components and message hooks, a computing device, and a computer-readable storage medium, which will be described in detail in the following embodiments.
[0022] See Figure 1 , Figure 1A flowchart is shown of a loosely coupled software architecture method based on multimodal components and message hooks according to an embodiment of this specification, specifically including the following steps.
[0023] Step 101: The sender encapsulates the business data and subsequent logic into a hook message, which contains the business data and a hook function for callback. Step 102: Send the hook message to the message bus. The message bus routes the hook message to the receiver registered to process that type of business data according to the type of business data. Step 103: The receiver extracts and processes business data from the received hook message; Step 104: After processing is complete, the receiver calls the hook function in the hook message to execute subsequent logic in the sender's context.
[0024] In this system, the sender can refer to a functional unit that actively initiates the interaction request, such as a user interface module or a business logic module. Business data can refer to the core information that the sender needs to pass to the receiver for processing, such as order numbers, text content, or image data. Subsequent logic can refer to a piece of processing code that the sender wants to execute automatically after the receiver completes its task, such as updating the interface, logging, or triggering subsequent operations. A hook message is a special communication data structure that bundles request data and callback logic together to form a self-contained communication unit. A hook function is a callable code block (such as a function object or lambda expression) that captures the sender's context information and can be safely executed within the sender's context. The message bus is the central communication hub of the system, responsible for receiving all hook messages and distributing them to registered receivers according to the business data type. The receiver is a functional unit responsible for processing specific business data, such as a data storage module or a computing module.
[0025] The aforementioned method will be further illustrated by a detailed embodiment below: In an online shopping system, the order module (sender) needs to generate an order, notify the inventory module to deduct inventory, and update the front-end page after the deduction is complete. The order module uses order details as business data and encapsulates the subsequent logic of "updating the front-end order status" into a hook function; the two together constitute a hook message. The order module sends this hook message by calling the sending interface provided by the message bus. The message bus routes the message to the inventory module (receiver) based on the type of business data (order details). The inventory module extracts the product information from the order details and performs the inventory deduction operation. After processing, the inventory module directly calls the hook function attached to the hook message. This hook function executes in the context of the captured order module, pushing an update of "order confirmed" to the front end, thus completing the entire order placement process. During this process, there are no direct method calls or compile-time dependencies between the order module and the inventory module, achieving complete decoupling.
[0026] The advantage of the aforementioned method lies in its ability to simplify and streamline bidirectional communication between modules by encapsulating business data and subsequent logic within a single hook message. The sender does not need to define additional callback interfaces or listen for events, and the receiver does not need to know any details about the sender; it only needs to call the hook function after processing the core business logic. This mechanism significantly reduces coupling between modules, making the code easier to maintain and extend.
[0027] As described above, the method also includes a step of managing the lifecycle of modules through a dynamic module manager, specifically including: Load or unload the sender or receiver using the dynamic module manager; During initialization, the module registers the message types it can handle with the message bus; Associate a weak reference token with the hook function. The weak reference token is used to characterize the lifecycle state of the sender that provides the hook function.
[0028] The Dynamic Module Manager is the central controller responsible for loading, unloading, starting, and stopping various functional modules in the system. Loading a module refers to reading the module's binary code (such as a dynamic link library) into memory and executing its initialization code. Unloading a module refers to removing the module from memory and releasing its resources. A weak reference token is a lightweight identifier that is not bound to a module's strong reference; it is only used to check if a module is still alive. Lifecycle status refers to the current stage of a module, such as "running," "stopped," or "unloaded."
[0029] Continuing with the aforementioned shopping system example, consider a server system requiring hot-update functionality. The dynamic module manager loads all necessary core modules upon startup, including the order module and the inventory module. Suppose a logic module named "Promotion Calculation Module" (the recipient) needs updating, and the administrator triggers an uninstallation command for this module. Before uninstallation, the dynamic module manager invalidates all weak reference tokens associated with this module. Previously, hook functions carried in hook messages sent by the order module were associated with weak reference tokens representing the order module. When the promotion calculation module attempts to call a hook function after processing business data, the runtime environment first checks the validity of the weak reference token. Since the order module is still online, the token is valid, and the call succeeds. In another scenario, if the order module is uninstalled, its token becomes invalid, the hook call is safely discarded, and the system does not crash. The new version of the promotion calculation module is then dynamically loaded and registers the message types it can handle with the message bus during initialization.
[0030] The introduction of a dynamic module manager and weak reference tokens enables the system to hot-plug modules while ensuring runtime safety. Modules can be updated independently without restarting the entire system, greatly improving availability and maintenance efficiency. The weak reference mechanism effectively prevents dangling pointer problems caused by module unloading, enhancing the system's robustness.
[0031] As described above, before the receiver calls the hook function, a step is also included to check the validity of the weak reference token: If the weak reference token is valid, the hook function is allowed to be executed; If the weak reference token is invalid, the hook function call is safely discarded.
[0032] The validity check is a runtime judgment process used to confirm whether the sender associated with the hook function still exists and is available. Safely discarding means not executing the hook function, which may log a warning or release related temporary resources, but ensures that the system will not crash as a result.
[0033] Continuing with the aforementioned hot update example, after the promotion calculation module finishes processing a promotion request, it prepares to call the hook function. Before the call, it queries the dynamic module manager using the weak reference token stored in the hook function wrapper to see if the order module is still online. The dynamic module manager maintains a global module liveness table and quickly returns "valid" or "invalid". If valid, the promotion calculation module executes the hook function and updates the promotion result. If invalid, the promotion calculation module skips the call and may log an entry saying "module unloaded, callback ignored". This checking mechanism ensures that even if the sender is unloaded during receiver processing, the system will not attempt to call a non-existent function, avoiding access violation errors.
[0034] The aforementioned steps, by performing weak reference token checks before invocation, provide a final line of defense for the system's dynamism. This allows all pending callbacks pointing to a module to be gracefully ignored after the module is unloaded, without causing a crash. This greatly simplifies resource cleanup during module unloading, making hot-plugging more reliable.
[0035] As described above, the method is applied in an entity component system architecture, where the sender and receiver are systems within the entity component system architecture.
[0036] Entity Component System Architecture is a software design pattern that separates data (components), entities (unique identifiers), and behavior (systems). A system is a logical unit that processes entities with a specific set of components, such as a physics system, a rendering system, or a combat system.
[0037] In a game engine employing an entity component system architecture, the aforementioned method is used to enhance inter-system collaboration. Assume there is a physics system (sender) and a rendering system (receiver). The physics system is responsible for detecting which entities have collided and using the collision results (such as a list of entity IDs) as business data. It also encapsulates the subsequent logic of "highlighting the materials of these entities" into hook functions and sends them to the message bus. The message bus routes the collision messages to the rendering system. The rendering system updates the rendering components of the entities based on the entity ID list, highlighting them on the screen. After processing, the rendering system calls the hook function, which executes within the physics system's context. This hook function may be used to record statistics about the collision event or trigger a new physics simulation. Throughout this process, the physics system and the rendering system interact only through hook messages and do not depend on each other.
[0038] By applying the aforementioned methods to the entity component system architecture, the entity component system, which was originally adept at data flow processing, gained powerful cross-system bidirectional communication capabilities. Collaboration between systems became clear and explicit, while maintaining a high degree of cohesion and independence for each system. This integration solved the problem of rigid inter-system interaction in traditional entity component systems and expanded the applicability of entity component systems.
[0039] As described above, in an entity component system architecture, the steps for workflow orchestration between systems via messages carrying hook functions include: After processing the entity, the first system generates a first hook message carrying a first hook function and sends the first hook message to the second system. After the second system processes the first hook message, it calls the first hook function, which contains the second hook message to be sent to the third system.
[0040] Workflow orchestration refers to linking the processing steps of multiple systems together to form an ordered business process. The first hook function is the logic provided by the first system and executed after the second system has finished processing. The second hook message is another hook message constructed and sent within the first hook function, used to trigger the processing of the third system.
[0041] In a complex role-playing game, when a player unleashes a "Fire Combo" skill, it needs to be processed sequentially by three systems: the combat system (calculating damage and applying a burning effect), the animation system (playing fire effect animations), and the log system (recording the combo data). After processing the player entity, the combat system (the first system) generates a hook message carrying a first hook function with the business data "deal fire damage to the target." The message bus routes this message to the animation system (the second system). The animation system plays the corresponding fire effect animation based on the business data. After playback, the animation system calls the first hook function. This first hook function is provided by the combat system and encapsulates the subsequent steps: it constructs a new hook message (the second hook message) with the business data "record the fire combo event" and includes the second hook function (potentially used to update achievement progress). The second hook message is sent to the message bus and routed to the log system (the third system). After recording the event, the log system calls the second hook function to update the achievement. In this way, the entire skill flow is broken down into three independent steps, naturally connected by a hook chain.
[0042] The preceding steps demonstrate a declarative business process orchestration approach. Complex multi-system collaboration is broken down into a series of atomic operations linked by hooks. Each system only needs to focus on its core responsibilities and the hooks that trigger the next step. This pattern is clearer and easier to debug than traditional callback nesting or global state machines, and modifications to the process only require adjusting the message sending logic in the hook functions without altering the internal implementations of the individual systems.
[0043] As described above, the hook message is a template class, which includes at least a sender identifier field, a business data field, and a hook function field.
[0044] The template class is a class definition that supports generic programming, allowing the type of business data to be passed as a parameter to adapt to the needs of different modules. The sender identifier field is a string or ID that uniquely identifies the sending module, used to locate the source during debugging, logging, or security verification. The business data field is a member that carries the actual business information, and its type is specified by the template parameter. The hook function field is a member that stores callable objects, such as std::function wrappers.
[0045] In the aforementioned game attack embodiment, the hook message is implemented as a C++ template class HookMessage.<t>When the combat system needs to send damage values, it instantiates a HookMessage. <int>The business data field is of type int and stores the damage value. The sender identifier field is set to a unique ID of the combat system, such as "CombatSystem_01". The hook function field stores a lambda expression that captures the context pointer of the combat system and implements the logic for updating combat statistics. The message bus processes HookMessage. <int>In this case, log entries can be recorded based on the sender identifier to facilitate tracing the message source. Once the animation system has finished processing, the lambda stored in the hook function field is called to complete the callback.
[0046] Hook messages are designed as template classes containing three core fields: sender identifier, business data, and hook function, making them a self-contained, type-safe communication primitive. The sender identifier enhances message traceability, the business data supports any type through the template, and the hook function encapsulates subsequent behaviors. This design allows hook messages to flexibly adapt to various application scenarios while maintaining code simplicity and type safety.
[0047] As described above, this also includes invalidating all weak reference tokens associated with a module when the dynamic module manager unloads the module.
[0048] Invalidating a weak reference token means marking the token as "unavailable," causing subsequent validity checks on the token to return invalid. This can be achieved by maintaining a mapping between tokens and module liveness states and updating this mapping upon uninstallation. All associated weak reference tokens refer to all tokens previously bound to hook functions via the dynamic module manager that point to this module.
[0049] Continuing with the aforementioned hot update example, suppose the dynamic module manager needs to unload a sender named "Order Module". At the start of the unloading process, the dynamic module manager first iterates through its internally maintained list of tokens, finds all weak reference tokens associated with the Order Module, and marks them as invalid. At this point, even if some unexecuted hook messages still hold these tokens (e.g., in the Inventory Module's pending queue), when the Inventory Module later attempts to call a hook function and perform a validity check, these tokens will return "invalid," and the call will be safely discarded. Only after completing the token invalidation process does the dynamic module manager actually perform the resource release and unloading operations for the Order Module. This sequence ensures that after the module is unloaded, no residual hook calls attempt to access the freed memory.
[0050] The aforementioned steps further enhance the system's security and dynamism by proactively invalidating the associated weak reference tokens when unloading modules. This ensures the timeliness and determinism of token invalidation, avoiding potential security issues caused by tokens not being invalidated in a timely manner. This mechanism is a crucial component in building highly available, hot-swappable modular systems.
[0051] In one overall embodiment, see Figure 2 The core architecture of this application demonstrates that module A encapsulates business data (Payload) and subsequent logic (HookFunction) into a unified HookMessage and sends it to the message bus. The message bus routes the message to module B based on the message type. After processing the Payload, module B directly executes the received HookFunction. This function executes safely within the context of module A (ensuring the module is not unloaded through weak reference tokens), thus achieving completely decoupled, secure, and reliable bidirectional communication. The dynamic module manager ensures system stability during module hot-plugging.
[0052] Specifically, the message hook communication framework includes the following: Hook Message Definition: Defines a new message type, HookMessage. <t>It is a template class that contains the following core fields: sender_id: A unique identifier for the sender.
[0053] payload: The message's payload (business data), of type T.
[0054] `hook_function`: A callable object (such as `std::function` or a function pointer), i.e., a "message hook," provided by the sender. This hook function typically captures context information from the sender (either by capturing a list via a lambda expression or by querying `sender_id`).
[0055] Message Bus and Routing: A central message bus is constructed to receive and route all HookMessages. Each module registers the message types it is interested in with the message bus. The message bus maintains a mapping between message types and a list of receiving modules. When a HookMessage is sent to the bus, the bus routes it to all modules registered as interested in that message payload type T.
[0056] Hook execution and context passing: The receiving module extracts the payload from the HookMessage for business processing.
[0057] After processing is complete, the receiving module directly calls the hook_function. This call can be executed synchronously in the processing thread, or it can be submitted to a specific thread pool or the sender's message queue for asynchronous execution to ensure thread safety.
[0058] When a hook function is executed, it can access the sender context captured at the time of its creation, thereby updating the sender state, triggering new methods of the sender, and even taking the processing result as a parameter.
[0059] Furthermore, the deep integration with the ECS architecture includes the following specific details: Inter-system communication: In the ECS architecture, each system can be considered an independent module. When system A needs system B to collaborate (for example, the physics system needs to notify the rendering system to highlight colliders after completing collision detection), system A creates a HookMessage. The payload contains the data required for collaboration (such as a list of entity IDs that collided), and the hook_function encapsulates the operation that system A needs to perform after receiving the "processing complete" signal from B (such as marking a specific entity as needing to be highlighted). After system B processes the collision data, it calls the hook, and subsequent operations of system A are triggered.
[0060] Hook-based workflow orchestration: Complex multi-system workflows can be implemented using hook chains. For example, an "attack" action might involve: combat system (calculating damage) -> animation system (playing hit animation) -> UI system (updating health bar). After processing the message, each system calls a hook, and the hook function contains the message to be sent to the next system. This forms a clear and traceable workflow.
[0061] Furthermore, dynamic module systems and lifecycle management include the following specific aspects: Module Manager: Implement a module manager to handle the loading and unloading of modules (dynamic libraries). Each module registers the message types it can process with the message bus during initialization.
[0062] Hook Lifetime and Safe Invocation: To ensure safety during module unloading, a weak reference mechanism is introduced. The `hook_function` is not bound to a strong reference to the sending module, but rather associated with a weak reference token representing the sending module. When a module is unloaded, the module manager invalidates all tokens associated with that module. When a receiver attempts to invoke the hook, the message bus or runtime environment first checks the token's validity. If invalid, the call is safely discarded, preventing dangling pointer issues.
[0063] Furthermore, the detailed design of the core components includes the following: Message bus: Serving as the central nervous system, it is implemented using either the observer pattern or the publish-subscribe pattern. It provides a RegisterHandler. <t>() and SendMessage <t>It includes interfaces such as (), and internally maintains a thread-safe message queue and dispatch mechanism.
[0064] Module abstraction layer: Defines a unified module interface IModule, requiring all modules to implement initialization, update, and unload methods. Modules interact with the message bus and module manager through the interface.
[0065] Hook function wrapper: Design a lightweight wrapper to manage hook functions and their associated weak reference tokens, provide a unified Invoke method, and perform a safety check before invocation.
[0066] The solution proposed in this application has the following significant effects: Achieve ultimate module decoupling and high cohesion: Modules interact only through message contracts, completely eliminating direct dependencies at compile time and runtime. Each module can be developed, compiled, tested, and deployed independently, significantly improving team collaboration efficiency and software maintainability in large projects.
[0067] Significantly simplifies the orchestration of complex asynchronous workflows: For complex business processes involving multiple modules and asynchronous operations, message hook chains can organize them into a clear message flow. This approach is more intuitive, easier to understand and debug than traditional callback nesting or state machine patterns, reducing the complexity of business logic.
[0068] Enhanced system scalability and flexibility: New functional modules can be dynamically loaded and integrated into the existing system at runtime, participating in existing workflows by registering the message types they can handle and the messages they may send. System functionality expansion and modification become more flexible, enabling rapid response to changing requirements.
[0069] Enhanced explicit expression and debuggability of the architecture: All interaction intentions between modules (including forward requests and reverse callbacks) are encapsulated in HookMessage, making data flow and control flow explicitly visible at the architectural level. This greatly facilitates visual debugging, performance profiling, and system behavior analysis.
[0070] Provides a robust foundation for low-code / no-code platforms: This highly declarative, message-based architecture is ideal as a backend engine for visual programming tools or low-code platforms. Users can orchestrate business processes by connecting "message-hook" nodes without writing underlying dependency management and callback code.
[0071] Compared with the prior art, the outstanding advantage of this invention lies in its creative combination of message passing, the concept of functions as first-class citizens, and the ECS data-driven concept, providing a unified, elegant, and powerful solution to the long-standing contradiction of "deep collaboration and thorough decoupling" in modular software development.
[0072] Corresponding to the above method embodiments, this specification also provides embodiments of a loosely coupled software architecture device based on multimodal components and message hooks. Figure 3 This specification illustrates a schematic diagram of a loosely coupled software architecture device based on multimodal components and message hooks, according to one embodiment of this specification. Figure 3 As shown, the device includes: The data encapsulation module 301 is configured to encapsulate business data and subsequent logic into hook messages, which contain business data and hook functions for callbacks. The data sending module 302 is configured to send hook messages to the message bus, and the message bus routes the hook messages to the receivers registered to process that type of business data according to the type of business data. The data extraction module 303 is configured to allow the receiver to extract and process business data from the received hook messages. The logic execution module 304 is configured so that, after processing is complete, the receiver calls the hook function in the hook message to execute subsequent logic in the sender's context.
[0073] One possible implementation also includes a step of managing the module's lifecycle through a dynamic module manager, specifically including: Load or unload the sender or receiver using the dynamic module manager; During initialization, the module registers the message types it can handle with the message bus; Associate a weak reference token with the hook function. The weak reference token is used to characterize the lifecycle state of the sender that provides the hook function.
[0074] In one possible implementation, a validity check of the weak reference token is included before the receiver calls the hook function: If the weak reference token is valid, the hook function is allowed to be executed; If the weak reference token is invalid, the hook function call is safely discarded.
[0075] In one possible implementation, the method is applied in an entity component system architecture, where the sender and receiver are systems within the entity component system architecture.
[0076] In one possible implementation, within an entity component system architecture, the steps for workflow orchestration between systems via messages carrying hook functions include: After processing the entity, the first system generates a first hook message carrying a first hook function and sends the first hook message to the second system. After the second system processes the first hook message, it calls the first hook function, which contains the second hook message to be sent to the third system.
[0077] In one possible implementation, the hook message is a template class that includes at least a sender identifier field, a business data field, and a hook function field.
[0078] One possible implementation also includes invalidating all weak reference tokens associated with a module when the dynamic module manager unloads the module.
[0079] The above is a schematic scheme of a loosely coupled software architecture device based on multimodal components and message hooks according to this embodiment. It should be noted that the technical solution of this loosely coupled software architecture device based on multimodal components and message hooks belongs to the same concept as the technical solution of the aforementioned loosely coupled software architecture method based on multimodal components and message hooks. Details not described in detail in the technical solution of the loosely coupled software architecture device based on multimodal components and message hooks can be found in the description of the technical solution of the aforementioned loosely coupled software architecture method based on multimodal components and message hooks.
[0080] Figure 4 A structural block diagram of a computing device 400 according to one embodiment of this specification is shown. The components of the computing device 400 include, but are not limited to, a memory 410 and a processor 420. The processor 420 is connected to the memory 410 via a bus 430, and a database 450 is used to store data.
[0081] The computing device 400 also includes an access device 440, which enables the computing device 400 to communicate via one or more networks 460. Examples of these networks include Public Switched Telephone Network (PSTN), Local Area Network (LAN), Wide Area Network (WAN), Personal Area Network (PAN), or combinations of communication networks such as the Internet. The access device 440 may include one or more of any type of wired or wireless network interface (e.g., a network interface card (NIC)), such as an IEEE 802.11 Wireless Local Area Network (WLAN) wireless interface, a Wi-MAX (Worldwide Interoperability for Microwave Access) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, or a Near Field Communication (NFC) interface.
[0082] In one embodiment of this specification, the aforementioned components of the computing device 400 and Figure 4 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 4 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0083] The computing device 400 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or personal computers (PCs). The computing device 400 can also be a mobile or stationary server.
[0084] The processor 420 executes computer-executable instructions that, when executed by the processor, implement the steps of the aforementioned low-coupling software architecture method based on multimodal components and message hooks. The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device and the technical solution of the aforementioned low-coupling software architecture method based on multimodal components and message hooks belong to the same concept. Details not described in detail in the technical solution of the computing device can be found in the description of the aforementioned low-coupling software architecture method based on multimodal components and message hooks.
[0085] An embodiment of this specification also provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the steps of the above-described loosely coupled software architecture method based on multimodal components and message hooks.
[0086] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium belongs to the same concept as the technical solution of the low-coupling software architecture method based on multimodal components and message hooks described above. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solution of the low-coupling software architecture method based on multimodal components and message hooks described above.
[0087] An embodiment of this specification also provides a computer program, wherein when the computer program is executed in a computer, it causes the computer to perform the steps of the above-described loosely coupled software architecture method based on multimodal components and message hooks.
[0088] The above is an illustrative example of a computer program in this embodiment. It should be noted that the technical solution of this computer program belongs to the same concept as the technical solution of the aforementioned low-coupling software architecture method based on multimodal components and message hooks. Details not described in detail in the computer program's technical solution can be found in the description of the aforementioned low-coupling software architecture method based on multimodal components and message hooks.
[0089] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0090] The computer instructions include computer program code, which may be in the form of source code, object code, executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content contained in the computer-readable medium may be appropriately added to or subtracted according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media may not include electrical carrier signals and telecommunication signals.
[0091] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments in this specification are not limited to the described order of actions, because according to the embodiments in this specification, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments in this specification.
[0092] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0093] The preferred embodiments disclosed above are merely illustrative of this specification. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the embodiments described herein. These embodiments are selected and specifically described in this specification to better explain the principles and practical applications of the embodiments, thereby enabling those skilled in the art to better understand and utilize this specification. This specification is limited only by the claims and their full scope and equivalents.< / t> < / t> < / t> < / int> < / int> < / t>
Claims
1. A loosely coupled software architecture method based on multimodal components and message hooks, characterized in that, include: The sender encapsulates the business data and subsequent logic into a hook message, which contains the business data and a hook function for callback. The hook message is sent to the message bus, which routes the hook message to the receiver registered to process that type of business data according to the type of the business data. The receiver extracts and processes the business data from the received hook message; After the processing is completed, the receiver calls the hook function in the hook message to execute the subsequent logic in the context of the sender.
2. The method according to claim 1, characterized in that, It also includes steps for managing the lifecycle of modules through a dynamic module manager, specifically including: The sender or receiver can be loaded or unloaded through the dynamic module manager; During initialization, the module registers the message types it can handle with the message bus; A weak reference token is associated with the hook function, the weak reference token being used to characterize the lifecycle state of the sender that provides the hook function.
3. The method according to claim 2, characterized in that, Before the receiver calls the hook function, the process also includes a step of checking the validity of the weak reference token: If the weak reference token is valid, then the hook function is allowed to be executed; If the weak reference token is invalid, the call to the hook function is safely discarded.
4. The method according to claim 1, characterized in that, The method is applied in an entity component system architecture, wherein the sender and the receiver are systems in the entity component system architecture.
5. The method according to claim 4, characterized in that, In an entity component system architecture, the steps for workflow orchestration between systems via messages carrying hook functions include: After processing the entity, the first system generates a first hook message carrying a first hook function and sends the first hook message to the second system. After the second system processes the first hook message, it calls the first hook function, which contains the second hook message to be sent to the third system.
6. The method according to claim 1, characterized in that, The hook message is a template class, which includes at least a sender identifier field, a business data field, and a hook function field.
7. The method according to claim 2, characterized in that, Also includes: When the dynamic module manager unloads a module, it invalidates all weak reference tokens associated with that module.
8. A loosely coupled software architecture device based on multimodal components and message hooks, characterized in that, include: The data encapsulation module is configured to encapsulate business data and subsequent logic into a hook message, wherein the hook message contains the business data and a hook function for callback. The data sending module is configured to send the hook message to the message bus, which routes the hook message to the receiver registered to process that type of business data according to the type of the business data. The data extraction module is configured to allow the receiver to extract and process the business data from the received hook message; The logic execution module is configured such that, after the processing is completed, the receiver calls the hook function in the hook message to execute the subsequent logic in the context of the sender.
9. A computing device, characterized in that, include: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions, which, when executed by the processor, implement the steps of the loosely coupled software architecture method based on multimodal components and message hooks as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the steps of the loosely coupled software architecture method based on multimodal components and message hooks as described in any one of claims 1 to 7.
