[Project_owners] Re: class vs contract ids

Ben Bucksch ben.bucksch.news at beonex.com
Fri Sep 12 06:32:48 EDT 2003


Pete Collins wrote:

>> am I correct in assuming that usage of a 128-bit identifer came about
>> because developers needed to be able to talk to _specific_ instances 
>> of a
>> class instead of whatever results a "contract id" might return?
>
> They are just variations of inique identifier strings. That's all.
> It is simply a way to put a unique stamp on a specific class 
> implementation.
>
>> Wouldn't it be better for an instance of Socket to use
>> "@mozilla.org/network/socket-transport-service;1"  instead of
>> "{c07e81e0-ef12-11d2-92b6-00105a1b0d64}"?  This would permit Socket 
>> to use
>> the "latest & greatest"
>
> Components.classesByID["{c07e81e0-ef12-11d2-92b6-00105a1b0d64}"];
> is the same thing as:
> Components.classes["@mozilla.org/network/socket-transport-service;1"];
> They both directly access of the underlying implementation class.

The one who asked the question was right (almost) - there is a small 
difference, it seems:
"Like a CID, a contract ID refers to an implementation rather than an 
interface, as an IID does. But a contract ID is not bound to any 
specific implementation, as the CID is, and is thus more general. 
Instead, a contract ID only specifies a given set of interfaces that it 
wants implemented, and any number of different CIDs may step in and fill 
that request. This difference between a contract ID and a CID is what 
makes it possible to override components."
<http://www.mozilla.org/projects/xpcom/book/cxc/html/quicktour2.html#1005456>, 
Creating XPCOM Components book

I've read elsewhere that using the ContractID is preferred. I personally 
like constants with numerical value, but oh well.

 From how I understood the above quote, a contract ID refers to any 
implementation of a given interface (or set of interfaces, any example 
of that?), while the CID refers to a specific implementation.


Neil,
the Creating Applications with Mozilla book has a subchapter about 
implementing JS components 
<http://books.mozdev.org/html/mozilla-chp-8-sect-2.html#mozilla-CHP-8-SECT-2.1>.

Both of the books have further info on XPCOM (the XPCOM book of course 
more detailed), if you need it. Thanks to all authros for making these 
books available online!

On a related note, I've recently seen Alec Flett's XPCOM inside 
presentation 
<http://www.mozilla.org/projects/xpcom/xpcom-inside/index.htm> and found 
it quite good.

Ben



More information about the Project_owners mailing list