Re: [GD-General] Eiffel
Brought to you by:
vexxed72
From: Jesse J. <jes...@mi...> - 2001-12-27 23:46:04
|
At 4:56 PM -0500 12/27/01, Thatcher Ulrich wrote: >On Dec 22, 2001 at 04:30 -0800, Jesse Jones wrote: >> >> Unfortunately MI has a bad reputation in C++. Even people who should >> know better like Scot Myers rag on it. But essentially all of the >> problems with MI in C++ are because of virtual base classes. So how >> do you avoid virtual base classes? By avoiding diamond shaped >> inheritance hierarchies. >> >> One way to do this is by using mixin classes. You have your main-line >> classes like Widget or Monster or whatever and then you have mixin >> classes like ReferenceCountedMixin or ObserverMixin or whatever. >> Mixins only descend from other mixins so you never wind up with the >> diamond of death. > >I've been pondering this. I've always depended on virtual inheritance >for effective mixins. For example, how do you implement smart >pointers to mixins of ref-counted classes, without virtual >inheritance? I assume you're talking about a smart pointer class that requires invasive changes to the object it's pointing at. For example, a smart pointer class that maintains ref counts and requires that the object have a common reference counted implementation. In general I think it's better to try to come up with a non-invasive design. However I have dealt with problems like this. For example, I used to have an Invariant class that allowed for DbC-style invariant checks. The class had a virtual Invariant method and a counter that was incremented when entering a public method and decremented when exiting a public method. But mixins still wanted to call the invariant so what I did was dynamic_cast the mixin this pointer to an Invariant* and call the Invariant method if the result wasn't NULL. However I've fairly recently dropped the Invariant class. -- Jesse |