设计模式问题

发布于 2024-10-21 05:03:48 字数 1723 浏览 3 评论 0原文

我当前的应用程序有一个 DataMgr 类,我将所有与数据相关的内容放入其中。这个类最近变得太大了,我想将它分成更小的部分以便于维护。

这就是我正在考虑的事情:

  • 创建一个 AbstractDataMgr 类,该类将包含应用程序中随处访问的所有变量。例如,将包含所有用户的 usersList ArrayCollection。

  • DataMgr 的所有较小部分都将扩展 AbstractDataMgr。例如,扩展 AbstractDataMgr 的 UsersDataMgr 类。这样,UsersDataMgr 就可以加载并填充 AbstractDataMgr 中的 usersList。另一个例子,SessionDataMgr 类关心我的应用程序中发生的一些播放会话。

我的问题是:

  1. 我的方向正确吗?

  2. 我想将每个较小的 DataMgr 类放在单独的模块中,以加快编译时间。这样,当我编译 SessionsModule 时,它​​就不会查看 UsersModule,从而减少编译时间。

这是我开始此线程的问题:在 SessionsModule 内部时,如何从 UsersDataMgr 获取用户信息(例如,通过调用函数 getUserData),而无需在 SessionsDataMgr 中导入 UsersDataMgr。因为如果我导入它,那么它将在 SessionsDataMgr 中编译...这是我不想要的。

我希望我没有让你感到困惑,我希望我能找到一些帮助。


更新1:

所以基本的问题是我有一个大型应用程序在我来之前设计得很糟糕。现在我正在努力让事情变得更好、更容易。

目前,编译完整的应用程序需要很长时间(大约 3-3:30 分钟)。这是由于多个问题造成的: 1- 框架中的文件太多,每次编译应用程序时都需要检查更改。 2- 其中一些文件包含大量数据(例如,信息表之一被硬编码到大小为 7.5MB 的文件内的大胖数组中)。

所以目前我花了很长时间来修复错误,这是因为编译时间很长。所以我尝试通过将应用程序分解为模块来解决这个问题。创建了三个模块后,我发现每个模块的编译时间也很长(大约2分钟)...

除了这个问题之外,现在我有另外3个大尺寸的swf,而不是一个大尺寸的swf。因此,我决定从这些模块中删除完整的框架,只包含所需的文件。一开始一切看起来都很好,直到我包含了 DataMgr...之后我必须包含所有框架才能编译时没有错误。这是因为 DataMgr 导入了很多框架。

所以我解决这个问题的第二步是划分DataMgr。我喜欢你的建议,这就是我打算这样做的...但是,我仍然有一个未解答的问题:

我拥有模块和划分 DataMgr 的目的是我不想在每个模块中包含完整的框架。相反,只有所需的文件。但是,如果在 SessionsDataMgr 模块中,我会调用:

UsersDataMgr.getInstance().getUserInfo( userId );

这意味着我必须在 SessionsDataMgr 中导入 UsersDataMgr...这也意味着(如果我理解正确的话)在编译 UsersDataMgr 时,编译器将检查 SessionsModule 的所有文件,同时也会检查 SessionsDataMgr 中的所有文件。这会增加 swf 文件的大小并增加编译时间。

  • 我对事情如何正常运作的理解正确吗?
  • 是否有解决此问题的方法,能够将两个模块完全分离,但在某些时候能够从另一个模块调用用户功能?

抱歉回复太长,感谢您的帮助。

My current application has a DataMgr class in which I put everything data-related. This class has grown too big recently and I want to split it into smaller pieces for easier maintenance.

This is what I am thinking about:

  • Create an AbstractDataMgr class that will have all the variables that will be accessed everywhere in the application. Example, a usersList ArrayCollection that will contain all users.

  • All smaller pieces of DataMgr will extend the AbstractDataMgr. Example, UsersDataMgr class that extends AbstractDataMgr. This way, UsersDataMgr gets to load and populate the usersList in the AbstractDataMgr. Another example, SessionDataMgr class that cares about some playing sessions that take place in my application.

My Questions are:

  1. Am I on the right track?

  2. I want to put each smaller DataMgr class in a separate module for faster compilation time. This way, when I compile the SessionsModule, it will not look at UsersModule and thus have less compilation time.

And this is my question for which I started this thread for: When inside SessionsModule, how to get users information from the UsersDataMgr (e.g., by calling a function getUserData) without having to import UsersDataMgr in SessionsDataMgr. Because if I imported it, then it will be compiled in the SessionsDataMgr... which I don't want.

I hope I didn't confuse you and I hope I can find some help.


UPDATE 1:

So the basic problem is that I have a large application that was badly designed before I come. Now I am trying to make things better and easier.

Currently, it takes long time to compile the full application right now (about 3-3:30 min.). This is due to multiple issues:
1- Too many files in the framework that need to be checked for changes everytime I compile the application.
2- Some of those files contain large amount of data (e.g., one of the information tables is hard-coded into a big fat array inside a file that is 7.5MB of size).

So currently it is taking me long time to fix bugs and that is because of the long compilation time. So I tried fixing this problem by breaking the application into modules. After creating three modules, I found out that each module's compilation time is also taking a long time (about 2min.)...

In addition to this problem, now instead of one large sized swf, I have 3 other swfs with large sized. So I decided to remove the full framework from these modules, and only include the required files. Everything was looking good at the beginning until I included the DataMgr... after which I had to include all the framework in order to compile without bugs. This is because the DataMgr imports lots of the framework in it.

So my second step in solving this problem is to divide the DataMgr. I like your suggestion, and that is how I was planning to do it... However, I still have one unanswered question:

My intention of having modules and dividing DataMgr is that I don't want to include the full framework in each modules. Rather, only the required files. However, if in the SessionsDataMgr module I would call:

UsersDataMgr.getInstance().getUserInfo( userId );

This means that I have to import UsersDataMgr inside the SessionsDataMgr... which also means (if I understand this correctly) that when compiling UsersDataMgr, the compiler will check all the files of the SessionsModule, but also will check all the files in SessionsDataMgr. This would increase the file size of the swf and will increase compilation time.

  • Is my understanding of how things work correctly?
  • Is there a solution to this problem to be able to separate both modules completely but be able at some point to user functions from the other module?

Sorry for the long reply, and thank you for you help.

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

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

发布评论

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

评论(1

她比我温柔 2024-10-28 05:03:48

从听起来你的 DataMgr 类确实尝试做太多事情。分拆无疑是一条出路。

抽象类旨在提供所有具体实现所需的功能。为了提供全局数据访问,您正在寻找的设计模式是Singleton

如何从 SessionsModule 获取用户信息:

UserDataProvider.getInstance().getAllUsers();
UserDataProvider.getInstance().getUserDetails(UserId:String);

希望这能让您走上正轨!如果您可以分享有关您的应用程序和 DataMgr 的其他职责的更多详细信息,我将很乐意帮助您制定出简洁且更高效的设计。

From the sounds of it your DataMgr class really is trying to do too much. Splitting it up is definitely the way to go.

Abstract classes are intended to provide functionality that is needed across all concrete implementations. To provide global data access, the design pattern you're looking for is Singleton

How you would get user information from the SessionsModule:

UserDataProvider.getInstance().getAllUsers();
UserDataProvider.getInstance().getUserDetails(UserId:String);

Hopefully this puts you on the right track! If you can share a few more details about your application and other responsibilities of the DataMgr I would be happy to help you work out a clean and more efficient design.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文