///////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2010 Wolfgang Kowarschick // // Permission is granted to copy, distribute and/or modify this document // under the terms of the WK License, Version 1.0 (WKL 1.0) or any later // version published by Wolfgang Kowarschick. ///////////////////////////////////////////////////////////////////////////////// package wk.pattern.singleton { /** * @autor Wolfgang Kowarschick * @category class * @langversion 3.0 */ public class WK_Multiton { ///////////////////////////////////////////////////////////////////////////// // Static Members ///////////////////////////////////////////////////////////////////////////// private static var vs_instances: Object = {}; // A hash map! public static function instance(p_class: Class): Object { var l_instance: Object = vs_instances[p_class]; if (l_instance == null) { l_instance = new p_class(); vs_instances[p_class] = l_instance; }; return l_instance; } public static function ensureSingleton(p_class: Class): void { if (vs_instances[p_class] != null) throw new Error(p_class + " is a singelton. Do not call the constructor directly!" ); } ///////////////////////////////////////////////////////////////////////////// // End of class ///////////////////////////////////////////////////////////////////////////// } } ///////////////////////////////////////////////////////////////////////////////// // End of File /////////////////////////////////////////////////////////////////////////////////