Skip to content

Instantly share code, notes, and snippets.

@k0t0vich
Created September 12, 2013 19:34
Show Gist options
  • Select an option

  • Save k0t0vich/6542711 to your computer and use it in GitHub Desktop.

Select an option

Save k0t0vich/6542711 to your computer and use it in GitHub Desktop.
Compile protected Singleton
// сам синглтон
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