Definición de módulo asíncrono (AMD) y acoplamiento estrecho

So I have been reading up on the CommonJs Modules spec and looking at the dojo implementation and google closure implementation. The concept is pretty cool but I had the question of tight coupling of your application using AMD.

Example from closure site:



 * Iterates over a list of note data objects, creates a Note instance
 * for each one, and tells the instance to build its DOM structure.
tutorial.notepad.makeNotes = function(data, noteContainer) {
  var notes = [];
  for (var i = 0; i < data.length; i++) {
    var note = 
      new tutorial.notepad.Note(data[i].title, data[i].content, noteContainer);
  return notes;

 * Manages the data and interface for a single note.
tutorial.notepad.Note = function(title, content, noteContainer) {
  this.title = title;
  this.content = content;
  this.parent = noteContainer;

 * Creates the DOM structure for the note and adds it to the document.
tutorial.notepad.Note.prototype.makeNoteDom = function() {
  // Create DOM structure to represent the note.
  this.headerElement = goog.dom.createDom('div',
      {'style': 'background-color:#EEE'}, this.title);
  this.contentElement = goog.dom.createDom('div', null, this.content);
  var newNote = goog.dom.createDom('div', null,
      this.headerElement, this.contentElement);

  // Add the note's DOM structure to the document.
  goog.dom.appendChild(this.parent, newNote);
  return new goog.ui.Zippy(this.headerElement, this.contentElement);

So my question isn't there tight coupling occurring here? If you provide tutorial.notepad to the application and some other module requires it and functionality changes within tutorial.notepad isn't there a tight coupling problem here. Basically you are chaining together modules that should be able to live on there own thus creating a fragile architecture.

I could be thinking about this wrong, if anyone can talk about this in an architecture context that would be appreciated or any resources about architecting a loosely coupled AMD architecture.

preguntado el 27 de agosto de 11 a las 16:08

Well, Closure is NO AMD-style. As you mentioned, Closure is tightly-coupled. It does NO use AMD. Therefore, the Closure Library is designed to be "modular" (similar to Dojo) but not "loose-coupling". Dojo from 1.6 onwards will be AMD-style loosely-coupled, although it will continue to have a global "dojo" object for backwards compatibility until 2.0. -

Gotcha. Is there any place I can read about how dojo is planning to implement AMD-style and loosely coupled? -

Start with documentation on the Dojo site, then you'll need to subscribe to the developers' mailing list -- that where up-coming verions are discussed. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.