Com
Principle note
--
Overview
Com
(Component Object Model,
Compent Object Model
) Yes
Microsoft
Proposed component standards, which not only define ComponentsProgramAnd provides the environment required for component programs.
I. Two process models:
In-process components: in the form of a dynamic link library (
. Dll
);
Out-of-process components: in the form of executable programs (
. Exe
);
The advantage of the In-process model is that the efficiency is high, but the component instability will cause the customer process to crash, so the component may compromise the customer.
The advantage of the out-of-process model is that the stability is good, and the component process does not endanger the customer program, but the efficiency is relatively low.
Ii. component software and software organization:
Component software: Software obtained by combining component models.
Software organization: Each component that constitutes the component software.
Iii. Objects and interfaces:
an object is a class (
class
) is an instance, and a class is a set of associated data and functions combined. Each object uses one
128
bit
guid
to identify, called
CLSID
(
class indentifer
) class Identifier or class
id
.
An interface is a set of logically related functions. Its functions are also called interface member functions. Use
128
The Globally Unique Identifier (
Globally Unique Identifier
) To identify the interface.
IV,
Com
Features
1
Language independence:
Com
The standard definition does not depend on a specific language. It uses a binaryCodeLevel standard, ratherSource codeLevel standard.
2
Process transparency:
Com
The library is responsible for locating component programs and managing component object creation and communication between objects and customers. This is transparent to users.
3
And reusability: two mechanisms are used to reuse objects.
inclusive mode: object
1
include objects
2
, when the object
1
objects to be used
2
, it can easily deliver the implementation to the object
2
. Although the object
1
and object
2
supports the same interface, but the object
1
called objects are implemented during interface implementation
2
.
Aggregation Method: Object
1
Simply put the object
2
To the customer.
1
No implementation object
2
But it takes the object
2
And the client program does not know the internal object.
2
.
Com
Principle Note 2 --
Com
Objects and interfaces
I,
Com
Object and
C ++
Object comparison:
1,
Encapsulation:
Com
The encapsulation of data members of an object takes the component module as the final boundary and is completely transparent to the object users. You can only access the attributes of an object through interface member functions.
Although 《
Com
Principles
C ++
The encapsulation feature of an object is only semantic encapsulation, which is visible to the object user. But considering that encapsulation must meet the following conditions (there is a clear boundary, a definite interface, and a protected internal implementation), I personally think there are not many differences between the two, it's just a different form of expression.
2,
Reusability:
Com
The Reusable object must be represented in
Com
The inclusion and aggregation of objects. One object can use all the functions of another object;
C ++
The reusability of objects is mainly reflected in the Inheritance Mechanism, which makes
C ++
Subclass not only can reuse the data structure and program code of its parent class, but also can be modified and expanded easily on the basis of the parent class code without affecting its use of the original class.
3,
Polymorphism:
Com
Object polymorphism can be reflected through its interface.
C ++
Objects are embodied through virtual functions and overloading.
II,
Com
Some features of the interface:
1,
Binary features:
The interface specification is not based on anyProgramming LanguageBut sets the binary level standard. Any language can describe interfaces as long as it has sufficient data expression capabilities, so that it can be used for application development related to component programs.
2,
Interface immutability:
An interface is a bridge between a Component client program and a component object. If the interface changes frequently, the customer program and component program also need to change, which is very unfavorable for the development of the application system, it does not conform to the idea of componentized programming.
3,
Inheritance (scalability)
According
Com
Standard, all interfaces must be
Iunknown
Derived, either directly or indirectly.
Com
Interface inheritance is not recommended, and the inheritance between interfaces can only be single inheritance.
4,
Polymorphism:
Polymorphism during running. As mentioned above
Com
Object polymorphism through
Com
Interface, we can often note multiple different
Com
The object implements the same interface, and the client program can call
Com
Object.
III,
Com
Object interface principles:
1,
For different interface pointers of the same object
Iunknow
The interface must be identical.
2,
Interface symmetry: a query on an interface should always be successful.
3,
Interface self-inverse: If you query from one interface pointer to another, then returning from the second interface pointer to the first interface pointer will succeed.
4,
Interface pass: If the second interface pointer is queried from the first interface pointer, the second interface pointer can be queried to the third interface pointer, from the first interface pointer, the third interface pointer can be queried.
5,
Time-independent API query: if an API pointer can be queried at a specific time point, the same API pointer can be queried at any time in the future.