开发者

Design Pattern Issue

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜