View Full Version : how to organize js classes in a larger projects
22 Nov 2006, 1:14 PM
I noticed that the RSS example has on Viewer class which has private members for the various layouts and public method for the functionality related to the RSS viewer.
Now in a larger app, there will potentially be more screens / pages under the top level layout so I was planning on having a top level class based on the project name (say FooBar) which had references to separate manager classes (RSS Manager, AdminManager, ProfileManager, CalendatManager etc). Does this make sense? Are there any design tips or recommendations?
22 Nov 2006, 1:41 PM
If I was doing it I'd do it similar. I'd have core class for application initialization - say "FooApplicatorizerish". It would have an init method that was in charge of initializing the application. It would also be in charge of brokering functionality, this way lazy initialization can be used. Beyond that a solid OO design in place (which it sounds like you have) and you should be ready to run.
By lazy init, I mean like RSS Manager, AdminManager, ProfileManager, CalendatManager could be initialized separately, in their own closure class but I think that in general is a bad idea. Keep a single point of entry. Add function like getAdminManager() which checks if it is null, and initializes it if it is. Lazy initialization is always a good idea.
A good example of how not to do it would be my blog. It has legacy code (blog.js) and semi legacy code (commentable.js) both doing their own initialization. When I wanted to add the Download dialog, I had to make a call out to the comment class and make sure it wasn't open. In general the way it all interacts is not ideal and I am hoping to have the time to refactor it all soon.
22 Nov 2006, 1:50 PM
Powered by vBulletin® Version 4.1.5 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.