Realization principle of hook mechanism in interface combination SDK

Source: Internet
Author: User
Tags implement

The previous article briefly introduced the Flex based interface Composition SDK, which uses the hook mechanism to implement UI part lifecycle management, master-details relationship building, and UI step injection. A hook is a clasp that can be understood as a transparent extension of an object by having additional functionality attached to it transparently. Hook mechanism can be applied to a variety of platforms, no language, it conveys a thought. The biggest advantage of using the hook mechanism to implement these features is that without adding user complexity, it can be fully compatible with the design based on the flex component, so that users do not feel the slightest sense that we are using the SDK. That is to say, the introduction of this hook mechanism, the functionality provided by the SDK is completely transparent to the developer, and the idea is cool. However, no solution is perfect, this hook mechanism in the resource release, event capture, need to be in a certain order, control these orders for the SDK maintenance personnel requirements are higher, a lack of attention, there will be inexplicable errors. In addition, the hook mechanism is slightly more difficult to implement.

The following figure is the hook mechanism implementation class diagram.

IDisposable interface for reference with the Microsoft Memory management model, Adobe Flex in memory management and GC to do very rough, its SDK memory leaks a lot, in the modular application, memory leaks particularly serious. So, when I was designing the SDK, I introduced some memory management ideas from Microsoft, but made a little change as needed. The SDK memory release is divided into 2 phases, the first of which is a predispose function implementation that frees the dependencies between class instances, and the second phase is the Postdispose function implementation, which frees up instance references. All hooks implement the IDisposable interface, which enables memory release.

Icomponenthook inherits from the IDisposable interface and defines the basic interface of a hook, consisting of Compositionmanager, component, ishooked attributes and hooks, unhook methods, Used to represent a combination manager, a hook-mounted component, whether to mount and execute a mount, and perform an uninstall.

Componenthook is the base class of all hooks, which implements the definition of the Compositionmanager, component, ishooked properties directly, and sets the mounted component and Unhook properties in the hook method and the Ishooked method.

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.