Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: 3 Jan 2006 07:58:21 -0800,    group: microsoft.public.platformsdk.com_ole        back       


Fundamental concept: Class factories   
Hello.  I have had peripheral experience with various COM technologies
over the years, and I'ver never been comfortable with the motivation
for having "class factories" (better referred to as object factories).
I understand that they are used to create instances of COM classes but
why are they really necessary...what problem do they solve?

The reason usually given is that it protects the client from having to
know how to construct an instance of a COM class...the client just has
to call the well-known method on the IClassFactory of the object
factory instance.

That's fine but the client still has to know how to construct an
instance of the class factory!  So it seems to me it just pushes the
problem back one level.  If a client wants an instance of a particular
COM class, it still has to know how to create _some_ COM object
specific to the COM class of which it wants an instance.

Can anyone enlighten me?

Thanks,
Dave
date: 3 Jan 2006 07:58:21 -0800   author:   UncleStoner

Re: Fundamental concept: Class factories   
Hi Dave,

> That's fine but the client still has to know how to construct an
> instance of the class factory!  So it seems to me it just pushes the
> problem back one level.  If a client wants an instance of a particular
> COM class, it still has to know how to create _some_ COM object
> specific to the COM class of which it wants an instance.

Class factories are necessary for out-of-process servers. On startup, an 
out-of-process server registers factories for objects it can create in a 
system-global table using CoRegisterClassObject.

Then, whenever a client does CoGetClassObject for a CLSID, the COM run-time 
can look it up in said table, and return the factory instance.

I guess it works the same way for in-proc servers for symmetry.

--
Best Regards,
Kim Grsman
date: Tue, 03 Jan 2006 08:35:23 -0800   author:   Kim Grsman

Re: Fundamental concept: Class factories   
Hmm, well that explains that...thanks.

I really wish COM books/websites/etc would simply state that rather
than trying to present object factories as useful in and of
themselves...especially since those books/websites/etc typically start
with inproc examples.
date: 3 Jan 2006 09:59:02 -0800   author:   UncleStoner

Re: Fundamental concept: Class factories   
Hello Dave,

> I really wish COM books/websites/etc would simply state that rather
> than trying to present object factories as useful in and of
> themselves...especially since those books/websites/etc typically start
> with inproc examples.

I agree, I didn't get it until last year. DllGetClassObject just seems roundaboutish 
until you think about CoRegisterClassObject.
Also, I think one reason inproc servers use the same mechanism is to allow 
them to be hosted by surrogate processes.

--
Best Regards,
Kim Grsman
date: Tue, 03 Jan 2006 10:46:19 -0800   author:   Kim Grsman

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us