blogGoodbye to the cross-platform bridge

finnianr's picture


Lately I have had a change of mind about using the bridge pattern to make cross-platform classes, like those used in the Vision2 GUI library for example. I now favor using either the object factory pattern, or the simpler explict creation type construct as for example:

  The _I and _IMP suffixes denote respectively, a deferred interface and current platform implementation.

The Cross-platform Bridge

This pattern can be expressed abstractly by the following two classes:



The main advantage of this pattern is that it hides from the developer-user the fact that the class relies on different implementations for each development platform. However my experience of using this pattern over many years, is that it leads to unweildly code that is relatively difficult to maintain and extend. Using a deferred interface parent class with mutiple cross-platform direct descendants, genarally makes for cleaner code that is easier to maintain and extend.

Object Factory Example

Here is an example of an object factory class that is shared from the class EL_MODULE_AUDIO_COMMAND:

A Command Factory


Using the Command Factory


Typical Platform Implemenation

Note that all features of the interface are exported to NONE. This enforces the intent that the class be only useable through the interface.  

A Code Comparison on Github

Lately I have eliminated all uses of the CP bridge pattern from the Eiffel-Loop library. For posterity I preserved some of the obsolete classes used for wrapping OS commands in a separate directory. You can see the differences in the implemenation on github here:

The new implemenation has an improved inheritance heirarchy. This is the EL_OS_COMMAND_I heirarchy found in the example program manage-mp3:  

Syndicate content