Turn to a com article

Source: Internet
Author: User
 the object-oriented idea is difficult to adapt to this distributed software model, so the componentized  Program  design idea has developed rapidly. According to the idea of componentized programming, complex applications are designed into small, single-functional component modules that can run on the same machine, it can also run on different machines. In order to implement such an application, some extremely detailed specifications are required between the build program and the build program. Only when the component program complies with these common specifications can the system operate normally. Therefore, OMG and Microsoft proposed the Common Object Request breakerarchitecture and COM (Component objectmodel) standards respectively. Currently, the CORBA model is mainly used on UNIX operating system platforms, com is mainly used on the Microsoft Windows operating system platform. In the com standard, a component program is also called a module. It can be a dynamic connection library (DLL) and called an in-process component (in-of-processcomponent) it can also be an executable program (exe) called out-of-process component ). the COM object is based on the binary executable  Code  level, the objects in C ++ and other languages are based on  Source Code . Therefore, COM objects are language independent. This feature uses Component Objects developed in different  programming languages  for interaction. On the Microsoft Windows system platform, the COM technology is applied to all layers of the system. From the underlying COM Object Management to the upper-layer application interaction, the com standard is used. Overview 
 com not only sets a standard for interaction between components, but also provides an environment for interaction. Because the interaction between component objects is not dependent on any specific language, therefore, com can also be a standard for collaborative development in different languages. OLE technology is based on the COM specification. Ole gives full play to the advantages of the COM standard, making applications on Windows operating systems highly interactive. Without the support of OLE, the Windows operating system would be inferior. However, the COM specification is not limited to OLE technology. In fact, OLE technology is only an application of COM. Over the past few years, OLE technology has shown great limitations in network interconnection, however, COM has shown great adaptability. The com standard consists of two parts: specification and implementation. The specification part defines the communication mechanism between components. These specifications do not depend on any specific language or operating system, it can be used in any language. The implementation part of the COM standard is the com library, which provides some core services for the specific implementation of the COM standard. Com is a software model for objects, so objects are one of its basic elements. Similar to the Object Concept in C ++, an object is an instance of a class, and a class is a group of related data and function groups and a definition together. Use an object application (or another object) to become a customer, and sometimes become an object user. An interface is a set of logically related functions. Its functions are also called interface member functions. Objects provide various forms of services to customers through interface member functions. In the com model, the object itself is invisible to the customer. When the customer requests the service, it can only be performed through the interface. Each interface is identified by a 128-bit GUID (guid, globally uniqueidentifier. The customer obtains the interface pointer through the guid. Through the interface pointer, the customer can call its corresponding member functions. In general, the interface remains unchanged. As long as the desired interface still exists in the build object, it can continue to use the service provided by this interface. Objects support multiple interfaces. Therefore, you can add interfaces to Upgrade Component Objects. The new interfaces do not affect the use of old interfaces. How do customers identify COM objects? Similar to the interface, each object is identified by a 128-bit guid, called CLSID (classidentifier, Class Identifier or class ID). It can be ensured that the object is identified by clsid (probability) global uniqueness. 
 as long as the system contains information about such COM objects and includes the module files (DLL or EXE files) of COM objects and the COM object entry points in the code, the client program can create a COM object through the CLSID. So how do customers use the services provided by COM objects? What do customers get? In fact, after the customer successfully creates an object, it obtains a pointer to an interface of the object. Because the COM Object implements at least one interface, the customer can call all services provided by this interface. However, the COM object can have its own State, which makes the customer feel the existence of the COM object. If the customer has two objects with the same CLSID at the same time, the two objects can have different states. The customer does not have to worry about how the COM object is implemented, and the relationship between the State data of the two objects (array or linked list ). Of course, the COM object can also be stateless. This COM object is mainly used to provide function services and can be used to replace the traditional API function interfaces to make the application programming interfaces more orderly, the organizational hierarchy is more advanced. In addition to the specifications, Com also has the implementation part, including some core system-level code, which is exactly the core code, in this way, objects can interact with customers at the binary code level through interfaces. In Microsoft Windows. the DLL file situation exists, including the following: (1) a small number of API functions are provided to create the com application on the client and server. On the client side, it mainly creates functions, while on the server side, it provides access support for some objects. (2) com searches for the local server, that is, the EXE program, and converts the program name and CLSID through the registry. (3) provides some standard memory control methods for applications to control the memory allocation in the process. 
 the com library is generally not implemented at the application layer, but at the operating system level. Therefore, an operating system has only one com library. In addition, the implementation of the COM library must depend on the specific system platform, especially the underlying standards of the system. The com library ensures that all components interact with each other in a uniform manner, and that, when writing a com application, we do not need to write a large amount of Basic Code necessary for COM Communication, instead, it directly uses the APIS provided by the COM library for programming, which greatly speeds up development. For example, the current version of the COM Library supports remote components, that is, Distributed COM. We do not need to write any network or RPC (Remote Procedure Call) code, in this way, programs can communicate with each other on the network. If we use an object-oriented language to implement COM objects, we can naturally use class classes to define objects. In C language, the concept of an object may become a logical concept. If two objects exist at the same time, you must know which object the operation is intended for in the interface implementation, this process can be guaranteed by the definition of the COM interface. The idea that the COM standard uses guid to identify COM objects is derived from the uuid (universallz unique identifier) adopted by OSF (Open softwarefoundation). UUID is defined as part of DCE (distributed computing environment, it is mainly used to identify both sides of RPC communication. In addition to encapsulation and reusability, C ++ objects also have an important feature of polymorphism. It is the polymorphism of C ++ objects that reflects the high abstraction of things in C ++ languages. COM objects also have polymorphism, however, such polymorphism can only be reflected through the interface of the COM object, just as the polymorphism of the C ++ object can be reflected through its (virtual) function. From the API to the COM interface, if we want to implement a word processing application system, it requires a dictionary function. According to the componentized program design method, we should naturally put the dictionary function into a component (. DLL. If the dictionary program finds  algorithms  or the dictionary library changes, as long as the interfaces between the application and components remain unchanged, then the new component program can still be used by the application system. This is the flexibility brought about by using component programs. To connect application systems and component programs and make them work collaboratively, the simplest way is to first define a group of dictionary functions, and this group of functions should be generalized as much as possible, do not add specific dictionary-related knowledge. 

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.