in4ray / firefly-sdk

Firefly - in4ray Gaming SDK
http://firefly.in4ray.com
Other
54 stars 11 forks source link

Use Singleton for TextureBundles #12

Closed VladimirCores closed 10 years ago

VladimirCores commented 10 years ago

Hello i find that the way of using Singleton Pattern for TextureBundle implementations are more pleasurable than many initialization for every single view. Please check it out:

private static var _instance:MenuTextures;

public function MenuTextures() { super(); }

public static function getInstance():MenuTextures { return _instance == null ? _instance = new MenuTextures() : _instance; }

Best Regards, Vladimir Minkin

rzarich commented 10 years ago

Hello Vladimir! First of all, thx you're using our framework.

As for implementation singleton pattern for TextureBundle, you don't need do this. We have already implemented this pattern inside of this class. It's not standart implementation of pattern using static "getInstance()" as in your example. You just can use "new TextureBundle()" in different places and real instance will be created ones. Please see implementation of https://github.com/in4ray/firefly-sdk/blob/master/firefly/src/com/firefly/core/textures/TextureBundle.as this class.

Example: var menuTextures1:MenuTextures = new MenuTextures(); var menuTextures2:MenuTextures = new MenuTextures();

In this example "menuTextures1" and "menuTextures2" use the same textures you have registered in the texture bundle.

VladimirCores commented 10 years ago

Ok i see it, it's good realization. But i have a little paranoia about creation the same object every time i need them, for me get instance of object is more understandable. Thank you.