Update: Gaia bridge pattern API

January 23rd, 2008 by Steven Sacks

Over on Jesse Warden's blog, Patrick Matte pointed out that the duplication of code in the bridge class (Gaia) was entirely unnecessary. In fact, the Gaia class doesn't even need to be instantiated. It literally consists of a public static getter that returns the gaia_internal var impl:IGaia.

This resulted in a savings of 872 bytes , or basically half the prior size (1.63k), per child swf! It's DRY, and makes maintaining the API that much simpler. Here is the updated version of the Gaia class that demonstrates just how simple it is to simulate _global, exclude.xml and maintain strict-typing.

package com.gaiaframework.api
{
        import com.gaiaframework.core.gaia_internal;

        public class Gaia
        {
                use namespace gaia_internal;
                gaia_internal static var impl:IGaia;

                public static function get api():IGaia
                {
                        return impl;
                }
        }
}

And to set it up is now just two lines:

use namespace gaia_internal;
Gaia.impl = GaiaImpl.birth();

I don't even think it qualifies as a Bridge pattern class anymore. It's just a static reference to the interface using an internal namespace to keep the reference from being overwritten. Technically, the implementation class is a Facade, and this just seems like a nifty trick to compile only the Interface and not the Facade itself, vs being a full-blown design pattern like Bridge, which this does not seem to be. Whatever it is, it rocks.

Posted in Actionscript, Gaia, Tips/Tricks

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

About Steven Sacks

I am a professional Flash developer with over 13 years of programming experience. I have consulted for high-profile agencies and companies in San Francisco, Los Angeles, Atlanta and New York, and developed numerous award-winning websites and rich internet applications for clients including Adobe, Fox Sports, FX Networks, Anheuser-Busch, GE, DirecTV, ESPN, The Weather Channel, Home Depot, and Coca-Cola.

I am the author of the open-source Gaia Framework for Adobe Flash, which dramatically reduces development time and makes developing Flash sites much easier.