Anyone that knows me offline has probably heard me singing the praises of signals. I really like the stricter typing of signals compared to events. For me, strict typing means that my code is checked by the compiler (instantly, at compile time) as apposed to being checked by the AVM (eventually, at runtime). I have had countless times where I have seen code fail due to the event types declared in the handler method being wrong, even when the string values are stored as variables instead of using literals. The checking that event handlers are added correctly is not checkableRead more
Background Reading The factory method pattern The Problem? You have a complex object, which has a lot of arguments in its constructor or you always want to construct the object using different sets of parameters. Examples? Socket Manager How? The constructor of my complex object: public function ComplicatedButton(colour:uint, mouseOverColour:uint, mouseOutColour:uint) { _mouseOverColour = mouseOverColour; _mouseOutColour = mouseOutColour; setUpGraphics(colour); addEventListeners(); } The using of the creation method: var redButton : ComplicatedButton = ComplicatedButton.getRedButton(); var blueButton : ComplicatedButton = ComplicatedButton.getBlueButton(); Why is it good? • It is easy to understand; it is a simple pattern that needs little extra code. It buildsRead more
Background Reading None The Problem? You want to ensure you have only a single instance of an object and want global access to it. This may be because the object uses a resource, such as sounds, or because the object needs a lot of configuration, such as a currency formatter, or needs global access, an event dispatcher. Examples? Currency formatter, sound controller, global event dispatcher How? The Singleton: package singletonpattern { /** * @author eamonn faherty */ public class SocketManagerSingleton { private static var _instace : SocketManagerSingleton; public static function getInstace() : SocketManagerSingleton { ensureInstanceExists(); return _instace; } private staticRead more