|
From: Frank V. C. <fr...@co...> - 2000-01-13 17:27:59
|
In light of the recent exchange here in regards to genericity in
collections, it brought up an interesting conversation I had with Tom
Maguire (a team member both here and on the job I have so my kids can
milk me for every dime I have..., sorry), about the Bridge
implementation.
As you all know, or maybe don't, I implemented the Bridge pattern where
the base abstraction has the data member for the implementation:
class Bridge : public CoreLinuxObject
{
...
protected:
CoreLinuxObjectPtr getImplementation( void );
private:
CoreLinuxObjectPtr theImplementation;
};
This means that when a derivation is using the protected accessor, in
order to perform the operation the bridge was called up to do, it would
have to cast the implementation to the type that the derivation
expected. In the example code, EngineBridge worked with Engine
implementations.
Now, with Tom I mentioned his comment "Typically this is really ugly
type checking code that is the hallmark of poor or shortsighted
analysis." in regards to the Java hashtable thread. I pointed out that
Bridge requires the derivation to do exactley that!!!
So I am wondering, should we be offering a choice of implementation
where possible? In the bridge case a possible scenario would be:
--------- In libcorelinux++ source -----------
// We keep the same Bridge we already have AND ADD
template < class Implementation >
class BridgeTemplate : public Bridge
{
...
protected:
Implementation * getImplementation( void )
{
return dynamic_cast<Implementation *>
(Bridge::getImplementation());
}
private:
};
// OR We keep the same Bridge we already have AND ADD
template < class Implementation >
class BridgeTemplate : public CoreLinuxObject
{
...
protected:
Implementation * getImplementation( void )
{
return theImplementation;
}
private:
Implementation * theImplementation;
};
------------------------------------------------------
Any opinions?
--
Frank V. Castellucci
http://corelinux.sourceforge.net
OOA/OOD/C++ Standards and Guidelines for Linux
|