我应该使用什么模式/名称?
我创建了一个处理我的项目文本的 Singleton 类。像这样的 Singleton 类的合适名称是什么?
- 文本管理器?
- 文本处理程序?
- 文本控制器?
这些名字的含义有区别吗?
更新: 该类将项目文本存储为 xml,并具有返回正确文本的方法。
function getText(uid : String) : String
I have created a Singleton class that handles my project texts. What is the appropriate name of a Singleton class like this?
- TextManager?
- TextHandler?
- TextController?
Is there a difference in meaning of these names?
UPDATE:
The class stores the project text as xml and have a method for returning the correct text.
function getText(uid : String) : String
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我想它不处理添加/删除/...(->管理)文本(可能只是加载),所以它不是一个“真正的”管理器< /强>。
它也不会“控制”文本(“您只能从...访问”、“如果...则返回该键的另一个值”) )。
该课程为您提供文本。
我想它是某种本地化文本提供程序,对吗?
那么为什么不将其命名为
LocalizedTextProvider
呢?I suppose it doesn't deal with adding/removing/... (-> managing) the texts (maybe just loading), so it isn't a "real" Manager.
It also doesn't "control" the texts (something "You're only accessible from ...", "Return another value for that key if ...").
The class provides you with texts.
I suppose it's some Kind of localized text provider, right?
So why don't you call it
LocalizedTextProvider
?我通常称之为
TextUtility
或
TextHelper
,“处理程序”的问题在于它意味着某种事件处理。与“控制器”相同,它在不同的上下文中具有不同的含义。
I usually call something like this
TextUtility
or
TextHelper
the problem with 'handler' is that it implies some sort of event handling. Same thing with 'Controller', it has meaning in a different context.
我相信 Controller 是为 MVC 模型“保留”的,但我可能是错的。 TextHandler 和 TextManager 可能更好,但至少在我工作的地方,通常不鼓励服务/类中的“管理器”,因为假设每个类“管理”某些东西(但这可能只是特定于文化的)。
从这三个中我会投票给 TextHandler。它还可能稍微取决于您的编程语言。
I believe Controller is 'reserved' for the MVC model but I may be wrong. TextHandler and TextManager may be better but at least at the place I work, 'Manager' in a service/class is generally discouraged since it is assumed that every class 'manages' something (this may just be culture-specific, though).
I'd vote for TextHandler out of those three. It may also depend slightly on your programming language.
对我来说,这实际上听起来像是一个服务或存储库......
TextService 还是 TextRepository?文本模型?
但让我退一步...单例模式是访问此类内容的一种非常糟糕的方式。如果您想了解我在说什么,只需谷歌“单例模式问题”即可。另外,在 AS3 中,您没有私有构造函数,因此您无法以纯粹的方式实现 Singleton 模式。
相反,我真的更喜欢通过“控制反转”(IoC)容器进行组合。 ActionScript 有很多这样的工具。它们可以非常轻量级,但它们以非常优雅的方式解耦您的组件。
很抱歉在这里注入我的想法... ymmv :)
编辑 - 有关消除单例模式的更多信息
我已经写了一些关于消除代码中单例的策略。本文是针对 C# 编写的,但所有相同的原则都适用。在那篇文章中,我没有明确谈论 IoC 容器。
这是一篇关于Flex 中的 IoC 的非常好的文章。此外,一些框架还为您提供 IoC 功能:
This actually sounds like a service or repository to me...
TextService or TextRepository? TextModel?
But let me back up a bit... the Singleton pattern is a pretty bad way of accessing something like this. Just google "Singleton pattern problems" if you want to see what I am talking about. Plus, in AS3, you don't have private constructors so you can't implement the Singleton pattern in a pure way.
Instead, I really prefer composition via "Inversion of Control" (IoC) containers. There are plenty of them out there for ActionScript. They can be really lightweight but they decouple your components in a really elegant way.
Sorry to inject my thoughts here... ymmv :)
EDIT -- More on eliminating Singleton pattern
I have written about several strategies on eliminating singletons in your code. This article was written for C#, but all the same principles apply. In that article, I DON't talk explicitly about IoC containers.
Here is a pretty good article about IoC in Flex. In addition, several frameworks give you IoC capabilities:
您提出的所有三个名称都可以以相同的方式解释。有些人更喜欢处理程序,而另一些人可能会说控制器……这确实是一个语义问题。无论您选择采用什么约定,只要保持一致即可。不过,您应该捕获的常见概念是您所描述的类没有执行任何操作。它应该只负责委派,因为这就是经典 MVC 范例中管理者对员工和控制者所做的事情。
All three of the names you proposed can all be interpreted in the same way. Some people prefer handlers while others might say controllers... it really is a matter of semantics. Whatever convention you choose to adopt just be consistent. The common notion that you should capture though is that the class which you are describing is not doing anything. It should only be in charge of delegating, since that's what managers do to employees and controllers do in the classic MVC paradigm.
因为我通常在事件/消息处理上下文中使用 Handler 。用于操作和 MVC 内容的控制器,我会选择不同的东西:
我通常为类保留帮助器,允许简单地将一些数据转换为视图中要使用的东西。
As I usually have Handler in the event/message handling context. Controller for actions and MVC stuff, I would go with something different:
I usually reserve Helpers for classes allowing to simply transform some data into something to be used in the view.
文本缓存?听起来你只是用它来存储和检索数据......
TextCache? Sounds like you are just using it to store and retrieve data...
为什么不:
ProjectNameTexts
Why not :
ProjectNameTexts