[Prev][Next][Index][Thread]
Re: why?
jt <gkt37@dial.pipex.com> wrote in message
387C849F.BC993358@dial.pipex.com">news:387C849F.BC993358@dial.pipex.com...
> Please tell me more about why MI is good/bad/misused/whatever. I feel
> that I may be missing out on a valuable facility.
It's remarkably useful in decorating classes with extra, consistent
behaviour. Any attempt to wrap COM, for example, is probably going to have
to use lots of MI-based mix-ins to provide the IUnknown functionality, the
threading model, the lifespan issues, etc. Without MI you would need dozens
of potential base classes in a bizarre and increasingly counter-intuitive
inheritance tree to inherit your implementation class from with names
probably along the lines of:
- CComApartmentServer
- CComApartmentTearoff
- CComApartmentStandard
- CComApartmentStack
- CComMultithreadServer
- CComMultithreadTearoff
- CComMultithreadStack
To prevent unnecessary code replication in this tree, you'll be bumping a
lot of functionality deeper into the inheritance tree making the tree far
more brittle as changes to one portion of it cascade ever further upward and
force recompiles of classes which may or may not actually be affected by the
changes.
You could get away without this by doing containment, but at some point this
is going to cause you a world of grief in managing a bewildering array of
objects and their lifespans. (Some of that grief is lost in a
garbage-collected language, of course, but not all of it by far.) Also,
containment-based solutions rely too heavily on run-time error detection for
my tastes.
With MI, the bizarre tree of functionality is replaced by a much smaller
list of mix-in classes. I would, instead of inheriting my object from
"CComMultithreadServer", say, inherit instead from both CComMultiThread and
CComLifespanServer. Since the two mix-in classes are completely orthoganal
in functionality there's little to no impact for me.
--
Michael T. Richter <mtr@ottawa.com> http://www.igs.net/~mtr/
"get a life. its a plastic box with wires in it."
-- Nadia Mizner <nadiam@onthenet.com.au> (in private correspondence)
References: