Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Layering in JS

 
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and thanks for the chance to ask about OO JS.

I'm used to think about layering in the context of a J2EE architecture, but when we face a js development what are the typical layers involved? Further, how can I manage to separate those layers other than using separate js files?

Thank you very much. Sorry for my bad use of English.

Antonio
[ August 26, 2008: Message edited by: Ulf Dittmer ]
 
Stoyan Stefanov
author
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Antonio, could you give me some more context or examples what do you mean by layers.

I think your English is excellent (but I'm a Bulgarian myself, so I could be wrong )
 
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, when I work on a design I usually separate concerns like persistence, presentation, domain, logging... in separate layers. Each layer could be a logical separation from the rest of the components and it's usually formed of various packages.

I guess if I tried to develop a project with much javascript I would need to separate some concerns in different modules too. Am I wrong? Of course I know I won't find such layers, but a few other like for example: one for objects, another for handlers, etc...

I mean there's not only the need to separate the code in classes as a OO aproach, but to separate those clases themselves. What I really can't be sure of, is the kind of concerns I should localize and separate when I start to design my project. The different coarse-grained responsibilities (using a typical GRASP term) I'll find if a face a project with much javascript.

Hope I explained myself :/ I did my best. Thank you very much for your answers. It's great to have you at the forums.

Antonio
[ August 26, 2008: Message edited by: Antonio Fornie ]
 
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid my post went to the second page. I gave it a chance to be answered

Thank you. Bye.

Antonio
[ August 27, 2008: Message edited by: Antonio Fornie ]
 
Stoyan Stefanov
author
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Antonio, I'm afraid I don't have any best practices for you. You just go with whatever you and your team feel comfortable with.

BTW, you can have packages-like functionality in JavaScript too. Actually, it's a good practice to have at least one, just to namespace your application and avoid naming collisions. This is achieved with simple object.



then you can do:



You can even come up with a convenience namespace() method to help with naming the "packages", so you can do stuff like:

 
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.

It's good to learn it. Furthermore, I can feel better now that I see I wasn't missing so many things about it

Bye.

Antonio
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic