Flex Model Singleton


/ Published in: ActionScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package
  2. {
  3. [Bindable]
  4. public class MainModel
  5. {
  6. private static var _instance:MainModel = new MainModel(ModelEnforcer);
  7.  
  8. public static function getInstance():MainModel
  9. {
  10. return _instance;
  11. }
  12.  
  13. public function MainModel(enforcer:Class)
  14. {
  15. if(enforcer != ModelEnforcer) {
  16. throw new Error("Use MainModel.getInstance to access model");
  17. }
  18. }
  19.  
  20. }
  21. }
  22.  
  23. class ModelEnforcer {}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.