AS3 内部和自定义命名空间
我有以下软件包:
spark
spark.engine
在 spark
中,我有一个类 SeCore
;在 spark.engine
中,我有 SeStepper
和 SeKeyboard
。
我想要实现的目标是让 SeCore
成为唯一可以创建 SeStepper
或 SeKeyboard
实例的类。这可以通过将 SeCore
移动到 spark.engine
包并将其他两个类设置为 internal
来实现,但我想要 <如果可能的话,将 code>SeCore 放在 spark
包中。
我尝试创建自己的名称空间来处理此问题,如下所示:
package spark.engine
{
import spark.namespaces.spark_core;
use namespace spark_core;
spark_core class SeStepper extends SeObject
{
//
}
}
但是我收到错误:
1116:用户定义的命名空间属性只能在顶部使用 类定义的级别。
我还可以采取其他方法来实现我所追求的目标吗?
I have the following packages:
spark
spark.engine
Within spark
I have a class SeCore
; and within spark.engine
I have SeStepper
and SeKeyboard
.
What I'm trying to achieve is have SeCore
as being the only class that can create an instance of SeStepper
or SeKeyboard
. This can be achieved by moving SeCore
into the spark.engine
package and making the other two classes internal
, but I'd like to have SeCore
in the spark
package if possible.
I've tried making my own namespace to handle this, like so:
package spark.engine
{
import spark.namespaces.spark_core;
use namespace spark_core;
spark_core class SeStepper extends SeObject
{
//
}
}
However I get the error:
1116: A user-defined namespace attribute can only be used at the top
level of a class definition.
Are there any other approaches I can take to achieve what I'm after?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
99% 的情况下,将任何内容标记为“内部”都是一个坏主意。最好对“禁区”类和成员有一个命名约定,并允许开发人员自行承担风险。将事物标记为“内部”或“私人”是应该很少做的事情,并且应该深思熟虑。
但是,您可以在运行时通过使用 SeCore 中的只读属性并从 SeStepper 和 SeKeyboard 检查其值来强制执行此行为。
以下是伪代码,有一段时间没有使用 AS3 了。
在 SeCore 中
在 SeStepper 中
99% of the time, marking anything as 'internal' is a bad idea. It's better to have a naming convention for 'off-limits' classes and members, and allow developers to go there at their own risk. Marking things as 'internal' or 'private' is something that should only be done rarely, and with great forethought.
However, you could enforce this behavior at run time by using a read-only property in SeCore and checking its value from SeStepper and SeKeyboard.
Following is pseudocode, haven't used AS3 in a while.
In SeCore
in SeStepper
我不能同意这个答案,我的意思是公开事情是邀请黑客的一种方式。我可以在我想要的任何上下文中在计算机上运行的任何闪存中执行任何公共函数,我什至可以覆盖它们在内存中的执行,因为它们很容易找到,而使用私有/内部函数执行类似的操作几乎是不可能的。
I can't agree with the answer, i mean making things public is way to invite hackers. I can execute any public functions in any flash running on my computer in any context i want, i can even override their execution in memory since they are easy to find, whereas doing something like that with private/internal functions is almost impossible.