Created
September 12, 2013 19:34
-
-
Save k0t0vich/6542711 to your computer and use it in GitHub Desktop.
Compile protected Singleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // сам синглтон | |
| package { | |
| public class Singleton { | |
| private static var _instance:Singleton; | |
| public var value:String = "всё ок"; | |
| public function Singleton(protector:Protector) { | |
| } | |
| static public function get instance():Singleton { | |
| if (!_instance) | |
| _instance = new Singleton( new Protector()); | |
| return _instance; | |
| } | |
| } | |
| } | |
| internal class Protector{ | |
| public function Protector() { | |
| super(); | |
| } | |
| } | |
| // использование | |
| .... | |
| trace (Singleton.instance.value); // всё ок | |
| // вот тут ошибка компиляции, т.к. никому кроме синглетона, | |
| // не получить доступ к классу Protecor | |
| var s:Singleton = new Singleton(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment