tags:

views:

160

answers:

5

Hello,

I'm new to COM. I started learning it. Frankly speaking, I hate it.

I'm neither clear about what it is? no why it exists.

Is this a programming methodology like OOP? Does programming languages must support it? (with some special keywords or something)

When I asked my prof about it, He said:

COM is a binary-stable way to do OOP. We need to know binary-layout (something..something..)

I've no idea what it means. Some people say it is used for code reuse. OOP does good job at that. Then why did this COM evolve?

What is it with C++ and COM? Where ever I see, COM is always described with abstract C++ examples. Is it only for C++?

Can any one tell me a case so that I could realize the need for COM.

Also can anyone tell me what are the requirements for learning this to write my own components?

+3  A: 

COM at is core is a way of providing a data passing contract which is independent of any specific language. It is provably not language depenedent as there are many languages which support COM (C++,C,.Net,Java implementations)

It practice it is useful for a couple of different examples

  1. Communication between different languages: Because COM is language independent, it is possible to use a COM to pass data between components in different languages. For instance you can use COM to talk between C++, Java and .Net code.
  2. Threading Semantics: COM allows you to define threading semantics for a particular component to ensure it is created in the appropriate thread context no matter where it is used
  3. General componentization
JaredPar
>>"there are many languages which support COM "So, a language must support it? like a language must support OOP? If so, why is it that I never heard of "Component Oriented Language like Object Oriented Language"?
claws
@claws, It's actually possible to implement a COM layer in a language without any language specific support. Essentially writing a COM serializer and message passer as an API. I *think* that's how Java's implementation works but it's been a LONG time since I dealt with that.
JaredPar
COM absolutely does NOT require language support. From the beginning it has been possible to create and use COM objects in plain ol' C. No language support, just a bunch of macros. The original C++ implementations of COM were also macro-based, with no language changes; even today I think the core of COM is still implemented via macros rather than language changes (there are helper types like _com_ptr_t, but these are helpers, not core).
itowlson
I think you and Jared are thinking about different things when you hear "support". You seem to be thinking about support by constructs in the language's grammar, but I believe Jared just meant support as in "there's an API for it".
Michael Borgwardt
A: 

After thinking a while, I suppose the best way to put it for you to grasp the idea would be:

COM is a way to extend Windows API and publish other custom libraries in the system, so that you can discover and work with those new APIs in the same fashion without a need to recompile your application.

COM objects are registered in the system (by adding some hooks into the Windows registry). After that is done, your application can query in run-time existence of those expected libraries, and based on their availability to decide how to proceed further (instead of crashing when a statically linked library not found).

This mechanism is supposed to be language-independent, so any application written in any language should be capable of calling those interfaces and invoking operation of those libraries. In practice, however, some languages do not support some COM types so they get limited COM abilities.

Answering your question in comments:

To use COM no need to install anything. Everything is already there, in the form of WinAPI functions, which you can simply call in your application. DllGetClassObject and CoGetClassObject are used to instantiate COM objects. CoRegisterClassObject is used to register COM objects contained in your libraries in the system.

In order to enable uniform creation and interaction with COM objects, their creation has been entrusted to class factories, these are sort of helper objects. You call CoGetClassObject and ask it to let you talk to the class factory of the object you need. Given the interface to that class library, you ask it to instantiate the object you need. Then you can manipulate the object through interfaces it exposes.

Have a look at this brief overview on the Wikipedia: Component Object Model

Developer Art
I see.. COM is for MS Windows. JavaBeans, CORBA are alternatives for COM on other Operating Systems. Right? Do I need to install any software to use COM alternative on other OSes?Exactly which component of MSWindows will be managing these components?
claws
COM can actually be used in the cross-platform environment, it's just its types need to be understood by all clients which is not always the case.
Developer Art
A: 

Component Object Model is a standard defined by Microsoft, for a language-independent binary object interface, i.e. it enables different OO languages to pass around objects and call methods on them.

Michael Borgwardt
The language need not be OO. It's possible, albeit really really weird, to use non-OO languages like C to communicate with COM components.
JaredPar
+2  A: 

COM was first created as a mechanism to allow Microsoft Office applications to communicate with one another, then, in it's second iteration it was modified and extended to become a specification for how binary code components could, if they were constructed according to the specification, communicate with each other, and share data, no matter what language or OS they were built upon (as long as the binary file (the compiled dll or exe) conformed to the COM specification.

The purpose was to allow "binary reuse" which means that a code component could be resued by multiple client code components, that the origianl code component knew nothing about, and which were not even in existence when the component was origiannly compiled. To quote from one of the original architects of COM, Don Box

" ... The design paradigm of COM was that component contracts are expresed as type definitions. This was a step forward from the world COM replaced, in which contracts were expressed only as simple functional entry points.In this respect, COM was a major advance because it brought the dymnamic loading of code and the type system together in a fairly consistent manner. "

Charles Bretana
A: 

Short simplistic answer: In Windows when some DLL is COM compliant, then your favorite programming environment can make use of it with one click.

RocketSurgeon