开发者

COM coobjects and interfaces C#

I am completely new to this and am following a tutorial on msdn: http://msdn.microsoft.com/en-us/library/aa645736(v=vs.71).aspx#vcwlkcominteroppart1cclienttutorialanchor2

My question is why do we use COM Interfaces AND COM CoClasses? It se开发者_如何转开发ems odd to instantiate an instance of a COM CoClass, instantiate a new object that is the old object but casted as the COM Interface.

I really am just wanting to grasp the ideology here...any help is useful.


The theory is to seprate the interface (what an object can do) from the implementation (how it does it or more specifically what specific code is instantiated to do it).

Defining types only as interfaces allows COM to specifiy how objects across multiple languages inter-operate; this being one of its main goals. Since the interface specification is a contract for how to pass data and invoke methods any language can expose a COM object without clients needing to know about the inner workings of the implementor (the CoClass).

This allows VB6, .net, C++, deplhi and any number of other languages to interoperate within the same application.

The wikipedia article on COM has some good background in this regard.


This is a basic design principle in software engineering, interface is a contract, in com world, coClass is a implementation. for COM, the interface can be defined in IDL, but implementation (coClass) can be done in VB, C++, .net etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜