Update: Gaia bridge pattern API
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
