单例类中的Flex [英] Singleton Class in Flex

查看:205
本文介绍了单例类中的Flex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个疑问,... ...在Flex中你将如何创建一个Singleton类...

I have a doubt,.... How would you create a Singleton class in Flex...

有没有类似的类名称的任何公约应EB辛格尔顿还是应该扩展任何其他类。

Is there any convention like the class name should eb Singleton or it should extend any other class.

多少Singleton类可以在一个项目有哪些?

How many Singleton class can a project have?

谁能说一个Singleton类的实时使用?

Can anyone say the real time usage of a Singleton class?

我打算让我的成分标签文本在Singleton类...这是个不错的办法。

I am planning to keep my components label texts in a Singleton class... Is it a good approach.

推荐答案

能否蠕虫问单身的!

有大约主要是创建单身由于AS3没有私有构造一些不同的选择。下面是我们使用该模式。

There are a few different options about creating singletons mainly due to AS3 not having private constructors. Here's the pattern we use.

package com.foo.bar {

    public class Blah {

        private static var instance : Blah;

        public function Blah( enforcer : SingletonEnforcer ) {}

        public static function getInstance() : Blah {
            if (!instance) {
                instance = new Blah( new SingletonEnforcer() );
            }
            return instance;
        }

        ...
    }
}
class SingletonEnforcer{}

请注意,该SingletonEnforcer类是内部所以只能用于由布拉赫类(有效)。没有人可以直接实例化类,他们必须要经过的getInstance()函数。

Note that the SingletonEnforcer class is internal so can only be used by the Blah class (effectively). No-one can directly instantiate the class, they have to go through the getInstance() function.

这篇关于单例类中的Flex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆