[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dlsym() and C++



Bert Peers wrote:

> > > One trick that I use is this. In the header file:
> > >  /* everything short of the constructor must be pure virtual */
> > This is exactly what ClanLib does. It's great that we agree on that one.
> 
> Anyway, Pierre has a point that the strong link C++ enforces
> between interface and implementation is a problem.  From
> what I've read about OLE, the COM model is a pretty
> neat way around this.  It works by putting the functions
> you can call in a separate object.  The actual object
> containing the data then has only 1 member, which
> returns a pointer to that interface sub-object.  Obviously,
> this one-and-only member can be made so that it returns
> a different pointer/interface according to a parameter,
> which gives you inheritance and polymorphism all
> in one shot.  It sounds neat (especially for M$  I guess
> they ripped it somewhere :) though I'm not sure this
> short explanation is sortof clear ;)

If you have a class that has only pure virtual methods, no property or
non-virtual methods, and a subclass of that one that implements the
methods and adds any properties needed, putting that subclass definition
in some place private to the library, you can make a newFoo() function
that "return new FooSubClass", which is kind of like a "mini-COM". The
real COM can do a whole lot of additionnal stuff, of course.

Everybody interested should check out
http://www.mozilla.org/projects/xpcom/, particularly the "Modularization
Techniques" part.

-- 
Pierre Phaneuf
Ludus Design, http://ludusdesign.com/