Before interfaces can be extended by other classes they have to be defined. During definition write up, you will encounter syntax errors, as with every other code you write in javascript. After fixing the syntax, you will likely encounter Definition Errors, which are CrxOop's equivalent of javascript syntax errors. These must also be fixed before anything happens. Please refer to the section on errors for more information.
After a definition, an interface can either be resgistered explicitly using crx_registerInterface() / crxOop.crx_registerInterface() which would allow you to give it a name, or registered implicitly during calls to other parts of the library, such as crx_new.
Explicit registration is the recommended way of registration, and you can either do it by assigning a definition to a variable and then calling crx_registerInterface(). In this case the interface can be refered to using the variable name of the definition, or the registered interface name.
var InterfaceDefinition =
{
//DEFINITION
};
crx_registerInterface("myNameSpace.myInterface", InterfaceDefinition);
var ClassDefinition =
{
IMPLEMENTS: [InterfaceDefinition]
//REST OF DEFINITION
}
//OR
var ClassDefinition =
{
IMPLEMENTS: ['myNameSpace.myInterface']
//REST OF DEFINITION
}
Or by passing the definition immediately to crx_registerInterface(), which is our prefered approach:
crx_registerInterface("myNameSpace.myInterface",
{
//DEFINITION
});
Note that there is no actual support for name spaces. The full string "myNameSpace.myInterface" is the name of the interface, and not just "myInterface". However the use of ".", or something similar, is useful to avoid name collisions. Also note that interface names can collide with class names and vice versa. Explicit registration is very useful when it comes to definition errors.
The following is an example of implicit registration:
var InterfaceDefinition =
{
//DEFINITION
};
var ClassDefinition =
{
IMPLEMENTS: [InterfaceDefinition]
//REST OF DEFINITION
}
var instance1 = crx_new(ClassDefinition);
Note that interfaces registered implicitly can not be re registered explicitly later on. Also note that interfaces that are not registered implicitly or explicitly do not exist as far as CrxOop is concerned until they are registered. This is important to keep in mind when encountering errors about missing definitions.