|resources:||Home Installation Mailing list Source code Bugs Screenshots Nightlies|
|reference:||Roadmap Error messages Code overview Debugger (prototype only) Playthroughs|
What is a
Programming has always had a problem: programs grow. A small program can fit in your head, but a large one needs some way of organising the complexity-- "programming in the large", as [DeRemer and Kron, 1975] put it. One way of doing that is with components.
A program is built out of components a little like the way a federal country is one big state made up of lots of little states. Each component is like a semi-independent program in its own right.
On the other hand, one of the most important rules of component-based design is that components should know as little about one another as possible. If a component needs to ask another component for something, it should have access only to a few functions and so on, not to the internals of the other component. You can make a request, but it's none of your business how the component carries the job out.
To this end, everything you might need to know about a particular component-- all the names of the functions you can call, and what parameters you must pass along with them-- is collected up into an interface. (Inside an interface, functions are known as methods.) For example, a component which controls a printer might have an interface containing methods to:
- print the text X at the current position
- turn on italics
- turn off italics
- start a new line
- spit out a whole page (form feed)
If an interface describes the way a component works, the component is said to implement that interface.
Interfaces are handled separately from components. That way you can have multiple components (controlling, for example, different kinds of printer) and treat them all the same way. It also means that a component can support multiple interfaces.
One last problem: how do you get started? If you're handed a component, how do you know whether it supports a particular interface? Well, there's a basic interface that every component must implement, containing the really basic methods. (The name of this interface differs on different component systems-- XPCOM calls it nsISupports, Microsoft call it IUnknown, and CORBA calls it something like CORBA::Object.) One of these really basic methods, generally called QueryInterface, takes an interface ID, tells you whether the component supports it, and (if it does) sets it up for you to use it.
Further reading: Component-based design is used all over the place: there's COM in Microsoft Windows, Bonobo in Gnome (which is based on CORBA, found pretty much everywhere), JavaBeans in Java, and of course XPCOM in Mozilla.