Difference between revisions of "Components and Interfaces"

From CDOT Wiki
Jump to: navigation, search
(Component)
Line 2: Line 2:
  
 
Components and Interfaces define and/or implement small pieces of modular code that can be reused in the codebase.
 
Components and Interfaces define and/or implement small pieces of modular code that can be reused in the codebase.
 +
 +
''For example, Necko is the network library which is made up of several components such as HTTP, FTP, and other network protocol definitions and implementations.''
  
 
=== Component ===
 
=== Component ===
Line 24: Line 26:
 
These components can be grouped together to become a Module. A component or several components (aka Module) are delivered as binary library. In Windows, libraries are .dll files; whereas, Unix libraries are DSO.
 
These components can be grouped together to become a Module. A component or several components (aka Module) are delivered as binary library. In Windows, libraries are .dll files; whereas, Unix libraries are DSO.
  
''For example, Necko is the network library which is made up of several components such as HTTP, FTP, and other network protocol implementations.''
+
 
 +
 
 +
''For example, the CookieManager Component can be called from Javascript code''
 +
 
 +
// xpconnect to cookiemanager
 +
// get the cookie manager component in JavaScript
 +
var cookiemanager = Components.classes["@mozilla.org/
 +
      cookiemanager;1"].getService();
 +
cookiemanager = cookiemanager.QueryInterface
 +
      (Components.interfaces.nsICookieManager);
 +
 
 +
// called as part of a largerDeleteAllCookies() function
 +
function FinalizeCookieDeletions() {
 +
  for (var c=0; c<deletedCookies.length; c++) {
 +
    cookiemanager.remove(deletedCookies[c].host,  
 +
                          deletedCookies[c].name,  
 +
                          deletedCookies[c].path);
 +
                         
 +
  }
 +
  deletedCookies.length = 0;
 +
}
 +
 
  
 
=== Interface ===
 
=== Interface ===

Revision as of 16:30, 4 October 2006

What are Components and Interfaces?

Components and Interfaces define and/or implement small pieces of modular code that can be reused in the codebase.

For example, Necko is the network library which is made up of several components such as HTTP, FTP, and other network protocol definitions and implementations.

Component

  • A component is a small piece of reusable code.
  • It is usually one of several in a module.
  • A module is a binary library that groups components that provide some functionality.

Interface

  • A interface defines the communication channels between components.
  • These interfaces are reused to define unique components with the same characteristics and communication channels.

Components and Interfaces in Mozilla

In Mozilla, there are several technologies used that build the codebase. You will find some lower level programming languages such as C/C++ in the core, and may find some higher level programming languages such as Javascript in extensions, components, etc...

These technologies are connected using the XPCOM, XPConnect, XPIDL, etc... With these frameworks, developers can break up software projects into components.

Component

XPCOM allows developers to connect their code to the rest of the Mozilla codebase. It is a cross platform technology which allows the code to be reusable, updateable, and modular.

These components can be grouped together to become a Module. A component or several components (aka Module) are delivered as binary library. In Windows, libraries are .dll files; whereas, Unix libraries are DSO.


For example, the CookieManager Component can be called from Javascript code

// xpconnect to cookiemanager 
// get the cookie manager component in JavaScript 
var cookiemanager = Components.classes["@mozilla.org/ 
     cookiemanager;1"].getService(); 
cookiemanager = cookiemanager.QueryInterface
     (Components.interfaces.nsICookieManager); 
 
// called as part of a largerDeleteAllCookies() function 
function FinalizeCookieDeletions() { 
  for (var c=0; c<deletedCookies.length; c++) { 
    cookiemanager.remove(deletedCookies[c].host, 
                         deletedCookies[c].name, 
                         deletedCookies[c].path); 
                          
  } 
  deletedCookies.length = 0; 
} 


Interface

Related Links

Examples