Background Reading The creation method pattern The Problem? You want to use objects that are created else where and are of a set type but the implementations may vary. Examples? SocketManager, or any thing that needs to be replace during unit testing. How? The constructor of my complex object: public class CharacterFactory { public static var factory : NonPlayerCharacterFactory; public static function getAPlayer() : IPlayer { return factory.getAButton(); } } The using of the creation method: var player:IPlayer = CharacterFactory. getAPlayer(); Why is it good? • It is easy to understand; it is a simple pattern that needs little extraRead 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 Read about the singleton The Problem? You want to have multiple instances of a singleton and want global access to them all. This may be because the objects use groups of resources, such as different groups of sounds, or because the objects need a lot of configuration, such as currency converters, or need global access, an event dispatcher. Examples? Currency converter, sound controller, global event dispatcher How? The Multiton: public class SocketManagerMultiton { private static var _instaces : Dictionary; public static const CHAT : String = “CHAT”; public static const WEATHER : String = “WEATHER”; public static functionRead 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
I recently did my first public talk! It was at LFPUG (London Flash Platform UserGroup). Here are the details I think it went really well. I had some very kind feedback via email and twitter and also on the night in person! A few people have requested that I upload the examples I used and the slides so here they are. Over the next few weeks I am going to be posting example patterns with more information, in more depth than I did on the night. If you want me to cover a pattern please post a comment with theRead more