Changes

Jump to: navigation, search

Components and Interfaces

2,644 bytes added, 23:54, 4 October 2006
Resources
== Short Description 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.
It is usually one of several == Components and Interfaces in a module.Mozilla ==
A module is a binary library In Mozilla, there are several technologies used that groups 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 that provide some functionality, etc...
These technologies are connected using the XPCOM, XPIDL, etc... With these frameworks, developers can break up software projects into components. === Interface Component ===A interface defines Using XPCOM supports the communication channels between componentsobject oriented approach, allowing code to encapsulate and inherent functionality and characteristics.
These interfaces are reused XPCOM allows developers to define unique components with connect their code to the rest of the same characteristics and communication channelsMozilla codebase.It is a cross platform technology which allows the code to be:
== Long Description ==* reusable* updateable* modular
=== ''For example, the CookieManager Component ===can be called from Javascript code''
In Mozilla, XPCOM is used // xpconnect to break up cookiemanager // get the software projects into componentscookie 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; }
For example, Necko is the network library which is made up of These components can be grouped together to become a Module. A component or several components such (aka Module) are delivered as HTTPbinary library. In Windows, FTPlibraries are .dll files; whereas, and other network protocol implementationsUnix libraries are DSO.
=== Interface ===
There are two fundamental issues in component and interface-based programming:
* lifetime (aka object ownership)
* interface querying (identifing components at run-time).
These issues are addressed by the nsISupports interface that every XPCOM object should implement.
 
The nsISupports interface is similar to the Object and other run-time interfaces built into Java and .NET.
 
The following is a simple example of an implemented nsISupports interface for the class Sample.
 
class Sample: public nsISupports {
private:
nsrefcnt mRefCnt;
public:
Sample();
virtual ~Sample();
NS_IMETHOD QueryInterface(const nsIID &aIID, void **aResult);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
};
 
nsISupports interface is explained well [http://www.mozilla.org/projects/xpcom/book/cxc/html/quicktour2.html#1003494 here].
== Related Links ==
*https://addons.mozilla.org/firefox/2230/
== Examples Resources == Links to Newsgroup:* [news://news.mozilla.org/netscape.public.mozilla.xpcom mozilla.xpcom newsgroup] Links to IRC Channels: * [irc://irc.mozilla.org/developers #Developers]
1
edit

Navigation menu