经理课程的目的是什么?

发布于 2024-10-12 23:57:41 字数 141 浏览 3 评论 0原文

我看到很多类都标有“Manager”。如何使用管理器类?

例如,它是否被这样的组合使用?:

var m: Mananger = new ManagerClass();
m.doSomething();

I see a lot of classes labelled "Manager". How is a manager class used?

For example, does it get used by composition like this?:

var m: Mananger = new ManagerClass();
m.doSomething();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

柠檬色的秋千 2024-10-19 23:57:42

管理器类是一些不适合其他地方的代码的常见垃圾场。他们也往往是或成为神类

Manager classes are the common dumping ground for code that somehow didn't fit somewhere else. They also tend to be or become god classes.

迷鸟归林 2024-10-19 23:57:42

像这样的类用于管理另一个类的一组对象,这些对象通常是资源。

例如,假设您有一个数据库连接池,每个连接都由 DBConnection 类的一个对象表示。

如果您的代码需要通过连接池连接到数据库,它只会向 DBConnection_Manager 类请求新连接。为什么我们需要经理类?

Manager 类将查询其 DBConnection 对象列表,并确定其中是否有任何对象未分配,并返回一个。如果所有都已分配,它将创建一个并添加到池中(受允许的最大连接限制)或将请求放入队列,或报告失败。

所有这些功能对调用者来说都是完全隐藏的——管理池的具体细节是 Manager 类的工作。

这只是一个具体的例子,但其思想是资源管理是集中的并封装在 Manager 类中,并且用户代码仅请求“资源”。

我不确定这种方法是否有真正的“设计模式”,尽管我发现至少一个网页是这样说的:http://www.eventhelix.com/realtimemantra/ManagerDesignPattern.htm


更新:在动作脚本的情况下,这样的类可用于管理声音、事件侦听器或 GUI小部件(例如上下文菜单)

Classes like that are used to manage a set of objects of another class, which are often resources.

For example, let's say you have a pool of database connections, each one represented by an object of DBConnection class.

If your code needs to connect to DB via a pool of connections, it will merely ask DBConnection_Manager class for a new connection. Why do we need the manager class?

The Manager class will consult its list of DBConnection objects, and determine if any of them is un-allocated, and return one. If all are allocated, it will either create one and add to the pool (subject to max connections allowed limit) or place the request on queue, or report back failure.

ALL of this functionality is full hidden from the caller - the nitty-gritty details of managing the pool are the job of the Manager class.

This is just a specific example, but the idea is that resource management is centralized and encapsulated withing a Manager class and the user code merely asks for "a resource".

I'm not sure if there's a bona-fide "design pattern" for this approach, though I found at least one web page that says so: http://www.eventhelix.com/realtimemantra/ManagerDesignPattern.htm


Update: in case of actionscript, such a class could be used to manage sounds, or event listeners, or GUI widgets (e.g. context menus)

堇色安年 2024-10-19 23:57:42

有些认为管理者是代码味道

Some consider managers to be a code smell

网白 2024-10-19 23:57:42

这通常意味着有人正在实现一种设计模式,但不知道(或不想使用)它的正式名称。您必须阅读代码才能得出任何有意义的结论。

it usually means somebody is implementing a design pattern and doesnt know (or doesnt want to use) the formal name for it. you'll have to read the code to draw any meaningful conclusions.

如梦初醒的夏天 2024-10-19 23:57:42

在我看来,管理器类应该在以下情况下使用:

  1. 需要处理多个对象
  2. 将对象列表传递给调用者是不够的,您应该提供一些高级功能,例如选择 maxmin one
  3. 管理的对象应该属于一个类(方便管理)

In my opinion, manager class should be used in these conditions:

  1. Multiple objects need to be process
  2. Pass object list to caller is not enough, you should provide some advance functions such as select the max or the min one
  3. The objects to be managed should belong to one class (manage easily)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文