Software methods and COM Support Based on Component Reuse

Source: Internet
Author: User
Tags msmq
Software methods and COM Support Based on Component Reuse

Zhang Yu
Computer College, Huazhong University of Science and Technology

SummaryAs a hot topic of research, component models have emerged in an endless stream in recent years. For the interoperability between them, a public component must be available.
The underlying framework analyzes various practical factors. com is a feasible choice. This article discusses the support of COM norms for Component Reuse and its development prospects.
The concept of reuse based on COM is introduced: service standardization is promoted based on interface standardization, and standards are set up for the development and use of reusable software.

KeywordsSoftware reuse, COM, distributed object, component, object-oriented

As a practical and effective software development method, Component reuse is receiving more and more attention and research. In recent years, with DNA, middleware, and other three layers
The rise of system structures and distributed objects has given greater meaning to the software architecture based on reusable components. So that we can repeat the component
In the sense of application, we should not only shorten the development cycle, improve the reliability of software quality, but also realize that component assembly-based development is in system maintenance (such
Version updates, function additions, deletions, etc.), distributed computing, and other aspects bring great convenience. The maintenance phase accounts for about 67% of the total cost of the software development cycle.
So the significance of Component Reuse for the entire software industry is self-evident. From the perspective of maintenance and distributed computing, Component reuse is to achieve
"Plug and Play ".

In traditional object-oriented programming languages, the reuse of classes based on inheritance mechanisms is only source code-Level Reuse.
Under the development trend of industry, this situation is very common.) it becomes meaningless. More importantly, after Association, Class components are just a logical
The illusory concept will not bring any convenience to future processing.

Microsoft has developed COM since the beginning of 1990s. With the continuous improvement of ole1, vbx components, ole2, ActiveX, and COM +, Microsoft has become
Mature component models provide powerful underlying support for Component reuse.

Encapsulation of a COM Object

Com is a binary standard that specifies the memory structure that a COM component should have. The interaction between COM objects is based entirely on this memory.
Therefore, the differences between different programming languages and application environments can be ignored to a large extent, solving the problem of re-Compiling and re-issuing.
. Binary Code-level compatibility requires the support of the operating system, but the method of COM Describing object connection is different from the traditional API-based shared system service.
After the connection is established, the underlying library of COM is no longer needed and the system resources are stopped. Compared with APIs, the operating system must always manage the connections between components.

Com uses the interface concept to completely encapsulate the functional properties of the component. Communication with the component must be performed through the interface. The interface is not only a logical
The corresponding physical memory structure (vtable) exists. An object can correspond to multiple interfaces, and one interface can also be composed of multiple
Objects, showing flexible polymorphism, and also providing convenience for version management. When using the new version of the component to replace the old version
The component implements interfaces of the old version (by means of inclusion, aggregation, and so on) to ensure its compatibility with the original software system.
) Can be used naturally.

The interface completely encapsulates internal functions and the specific implementation of attributes, so that the COM object is displayed as a "black box" structure and fully complies with the requirements of the object-oriented system.
COM components do not have the "weak coupling" feature widely advocated due to excessive emphasis on interfaces. However, Microsoft has always
Based on the immutability of interfaces, this paper tries to use interface standardization to promote service standardization and build a practical framework for Software Reuse Based on interfaces.
A considerable part of ActiveX technical specifications are determined by defining standard interfaces and their logical relationships.

2. Automation

When considering the specific implementation of calling the member functions in the interface, we will find that this implementation needs to be completely different from the general specification due to the special nature of the components.
The problems to be solved are: how to identify a component in the source program (physically, there is an existing binary code with certain functions)
For the call of specific functions in the component, how will the compiler handle the call, how to test the parameters, and how to collect the returned values.

In the old programming mode, a descriptive file that fully defines the component is required to solve the above problem. In addition, the format of the descriptive file is
It must fully comply with the syntax of the programming language used. This creates the following conflicts. First, configure different versions for each release component.
The description file is not feasible in practice. Second, even if such a header file is automatically converted through the Type Library, this conversion is provided for various programming languages.
Changing tools is also not feasible. Third, the data types used in components do not always correspond to the target programming language. Fourth, this clumsy
The implementation method is far from the component's "plug-and-play" concept, which is unacceptable to programmers.

Aiming at the above problems, the COM specification puts forward the automation technology, which makes it better to achieve dynamic binding of the symbol-based navigation. idispatch.
Key Interfaces.

Class idispatch: Public iunknown

{

Public:

Virtual hresult gettypeinfocount (uint * pctinfo) = 0;

Virtual hresult gettypeinfo (uint itinfo, lcid

Lcid, itypeinfo ** pptinfo) = 0;

Virtual hresult getidsofnames (refiid riid, lpolestr *

Rgsznames, uint cnames, lcid, dispid * rgdispid) = 0;

Virtual hresult invoke (dispid dispidmember, refiid

Riid, lcid, word wflags, dispparams * pdispparams,

Variant * pvarresult, exceinfo * p1_info,

Uint * puargerr) = 0;

};

In an Automation Object, each member function corresponds to a distribution ID (dispid). The service navigator invoke uses this distribution ID to establish and target
Function connection. You can use getidsofname to map the symbol (function name) to id. Therefore, the application has a unified interface to use
Components.

For compatibility issues with data types, Microsoft provides a blunt solution to define a big data structure as "all-encompassing" as possible
Variant

Typedef struct tagvariant

{

Vartype VT; // type indication

Union

{// Value Type

Short ival;

Long lval;

Byte bval;

Float fltval;

......

// Reference type

Short * pival;

......

Iunknown ** ppunkval;

Idispatch ** ppdispval;

Variant * pvarval;

Void * byref;

};

};

The transmission of parameters and return values between an automation object and its Callers must be within the range of variant. Different types of variant Parameters
The conversion between numbers can be implemented in invoke, providing programmers with a more intelligent Programming Interface (as implemented in VB ).

Com specifies a required basic interface iunknown for All component objects. This defines not only the most basic public service, but also
The pointer to the iunknown interface is objectively the object identifier of the component instance. In addition to object lifetime management, this object identifier also enables the COM Component
With the self-explanatory feature, you can query all interfaces implemented by the object by calling the member function QueryInterface of the iunknown interface.
.

However, the advantages of the above automation are at the cost of data type restrictions and performance loss. Although the compiler can
Bind before the line (check the parameter type, convert the symbol to the distribution ID), but the most time-consuming invoke is difficult to optimize. Therefore, com specifies a dual interface mechanism.
It provides programmers with the freedom to choose between dynamic binding and static joint editing. At the same time, the existence of automation technology is also the scripting language (VBScript,
Javascript) provides vitality.

3. Inclusiveness and aggregation

As an important feature of object-oriented systems, com supports two types of reuse models: inment and aggregation.
This is consistent, but the implementation method is different.

Considering the inclusiveness, assume that there is already a COM Object A that implements the ireuseinterface interface. Due to the new requirements, we need to implement a new
COM object B, which must implement both the interface ireuseinterface and the interface inewinterface, and the server provided by the ireuseinterface
The interface of object A is basically the same as that of object A. As long as the newly added function is implemented, the development of object B can be completed. The most intuitive idea is to implement the internal function of object B.
"Inclusive" is an instance of object A. all calls to the ireuseinterface member function of interface B are simply forwarded to object a internally.
Customers of B do not need to know the existence of A. This inclusive relationship can be expressed as follows:

The inclusive model is more flexible in implementation. It can forward the call to the internal object before and after some localization processing, so as to make up for a and B's respective
The function of the ireuseinterface is slightly different.

In the above example, if the ireuseinterface of B is fully functional in line with the implementation of a, no changes are required.
Aggregate model to implement B. object B itself does not implement the interface ireuseinterface, it only implements the interface inewinterface. When B requests
During the ireuseinterface interface, object B passes the ireuseinterface interface pointer of object A to the client program. Therefore, the customer directly communicates with.
InterAction (although it does not know the existence of object a). Shows the implementation of the aggregation model:

Of course, the aggregation model is more complex than the inclusive model in iunknown pointer processing, and the cooperation between the two parties is required.
The feature of aggregation is supported, but aggregation reflects the reuse of component software in the true sense. the reusability of inclusion is only reflected in the comparison of the client server model.
The nesting relationship between customer programs and component programs is essentially different from that of inclusive and aggregated programs.

4. Unified Data Transmission and message transmission

In application systems developed based on software reuse, Each discrete component object must collaborate to complete a specific task logic.
It is far from enough to transmit only parameter information in a complex collaboration relationship. Standard Solutions and events for data exchange between applications and communication between messages must be provided.
Mechanism.

In both aspects, com provides mature specifications, that is, unified data transmission (UDT, uniform data transfer) and MSMQ.

As we all know, Ole programs use the clipboard to transmit connection object information, which is a typical UDT application.
This includes two aspects: first, the unification of data formats, and second, the establishment of transmission protocols.
"As an information entity, it exposes its internal information through the idataobject interface. Because the data object itself is a COM object, it can not only express
General structured information can also express some unstructured information.

A transfer protocol task is to pass the idataobject interface pointer provided by a component to another component object.
The idataobject interface pointer can be used to obtain the required data using its member functions. The specific implementation of the transfer protocol is completely separated from the data exchange.
To maximize compatibility with the original system, you can easily expand the Protocol. More common transfer protocols include clipboard, "drag-and-drop" Technology
In addition, to adapt to some real-time applications, Com also provides a "Data Change Notification" mechanism to expand data objects and customer programs
Mutual communication. Microsoft Message Queue (MSMQ) Version 1 is a new feature of the Windows NT operating system.
Reliable information communication for key tasks on the network. In contrast to most modern applications, MSMQ is based on
The message queuing model is used to provide asynchronous, loosely coupled, and reliable network communication. For the purpose of function reuse and standardization, MSMQ uses message-oriented
(Mom message_oriented middleware). MOM provides a basic structure for communication between queues and messages. Applications write data to queues.
When a message is imported, the message middleware transmits the message to the requested queue, and another application (or another component of the same application) reads the message from the target queue.
Retrieve and process the message. The message content is completely controlled by the read/write queue application. MSMQ supports a wide range of queue types. Public Application teams
Columns are visible to MSMQ users because they are published on a naming server, that is, mqis (Message Queue Information Store, message
Queue information storage). The MSMQ client can query mqis to determine whether a public application queue exists and which computer is the host.
On the one hand, the private application queue is not released in mqis. Therefore, to send messages to the private queue, you must know the host of the queue in detail.

Summary

In the field of enterprise application systems, Component reuse has become clear and clear because of the support of the three-layer architecture. It is applied in Windows DNA framework.
The system is divided into the presentation layer, business layer and data layer. The business layer can also be divided into multiple sub-layers as needed. the reuse of the presentation layer and data layer has
It is quite standardized, such as various class libraries that support GUI development, ActiveX controls, oledb, ODBC, etc. The reuse of components focuses on the business processing layer.
In order to clearly classify various services in the business world and standardize east service interfaces, the architecture and Component Reuse can be effectively realized.
.

With the release of Windows 2000, some integration of COM + As COM, DCOM, and MTS will soon emerge, which is more closely integrated with the operating system.
COM + provides better support for load balancing, security, message event models, and MTS services. At the same time, part of the features of COM + will be implemented in the next generation compiler.
(Visual Studio 7.0) makes the componentized program design more natural and friendly. With the publication of COM +, from now to the future, com will
Become a Windows-based component-oriented software development path.

References

① Stephen R. schach, software engineering with Java, McGraw-Hill

② Component object model specification, Microsoft Corp., 1993

③ Pan aimin, Principle and Application of COM, Tsinghua University Press

④ Yuan Xiaoling, component technology-the new dawn of enterprise management information system development, computer engineering and Application

May 9

⑤ Xu zhengquan, Xing ting, heterogeneous Reusable Software Component Attribute Model, Computer Application Research

⑥ Laixin and Deng tieqing, Research and Practice on integration of distributed objects and WWW technology, computer engineering and application,

May 7

7 Rogerson Dale, inside COM, Microsoft Press, 1997. ISBN 1572313498.

Alibaba Don benage Azam Mirza, building enterprise solutions with Visual Studio

6.0, Macmillan computer publishing U. S.

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.