[Project_owners] Re: class vs contract ids

Pete Collins pete at mozdev.org
Thu Sep 11 18:21:18 EDT 2003


  > since nobody seems to discuss (groups.google.com, google, etc) _why_...
> 
> 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" instead of requiring Mozilla to always include
> c07e81....


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.

To get an instance of the service:

 
Components.classesByID["{c07e81e0-ef12-11d2-92b6-00105a1b0d64}"].getService(Components.interfaces.nsISocketTransportService);

or equally:

 
Components.classes["@mozilla.org/network/socket-transport-service;1"].getService(Components.interfaces.nsISocketTransportService)

Six in one, half a dozen in the other.  :-)

Remember nsIScoketTransportService is *service* running in a single 
instance. The "getService" call slaps the public interface

nsISocketTransportService 
(http://lxr.mozilla.org/seamonkey/source/netwerk/base/public/nsISocketTransportService.idl)

onto the implementation class. There may be more than one 
iimplementation for a public interface, but that is rarely found in Mozilla.

In xpcom there are services and instances. The above example sites a 
service.

> I've noticed Chatzilla uses the canonical id, but that could be old habits
> ("it's always worked before...").

Both class ID's and Contract ID's are canonical. They are two ways of 
identifying the class. (Just to make things more confusing)

One is readable friendly the other is not.

It is just one way to do it,  I prefer using an identifier (or 
ContractID)  I can read.  :-)

> thank you for your time.

np

I'm posting this response to the project_owners news group. I think 
others could benefit.


--pete

-- 
Pete Collins
www.mozdev.org
www.mozdevgroup.com




More information about the Project_owners mailing list