Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I run into this same problem quite often. First, I create a namespace and then add modules to this namespace. Then issue I always run into is how best to initialize the application? Naturally, each module has its own startup procedure so should this data(not code in some cases, just a list of items to run) stay with the module? Or should there be a startup procedure in the global namespace which has the startup data for ALL the modules.

Which is the more robust way of organizing this situation? Should some things be made centralized or should there be strict adherence to modules encapsulating everything about themselves?

Though this is a general architecture questions, Javascript centric answers would be really appreciated!

share|improve this question

closed as unclear what you're asking by gnat, MichaelT, GlenH7, Kilian Foth, Bart van Ingen Schenau Sep 26 '13 at 7:26

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
What language is this? There are different approaches and conventions for different languages. –  MichaelT Jun 28 '13 at 15:08
    
javascript in this case –  Joe Jun 28 '13 at 15:12
    
Your question title and body seem to be asking different questions. Your title is about modules accessing data outside their scope. Your body is about initialization. Are you asking about accessing data in other modules or about initialization? –  Aaron Kurtzhals Aug 9 '13 at 15:59

3 Answers 3

Some data/scope is always given for any module, because they all run as part of the same application. It doesn't make sense to let every module load this for itself.

But if you distribute aliases for the data between modules, you can get into trouble. (Race conditions etc.). So be careful.

share|improve this answer

It all depends on your needs what your script will do. You may call the procedure which will initialize the data for all listed modules then it may occur that by now you required no manipulation on data and but later on future it is demanded. And yes the race condition as stated above may bring you in trouble. So I recommend first analyze your script how's the flow in operation and there by decide how to make initialization.

share|improve this answer

OSGi is a framework used for inter-module communication. You can set up your modules to write/read from/to the osgi service, and hence setting up a channel to exchange data between modules.

Can this be done in Java script ? I am not sure but a google search does throw up a few interesting links which can be further explored

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.