CrxOop CrxOop: Bringing Object Oriented Programming, and Proper Prototype Based Programming, To Javascript
The aim of the library documented below is to provide developers with a solution to allow development using interfaces and classes as they are known in other object oriented programming (OOP) languages such as C++, C#, Java and PHP. Further more, V1.4 introduces structures, a generalization of the concept of prototypal inheritance, known here as POBP.
Subject
Body*
Email
SUBMIT CLOSE
Menu

4.0 Interfaces

Initially, in v1.0 of CrxOop, CrxOop did not allow the creation of pure virtual methods, while at the same time the Javscript technology does not allow a satisfactory implementation of multiple inheritance for classes. This leads to the implementation of what are called interfaces in Java. In C++, these would be classes with only public pure virtual methods.

Note the following:

  • Interfaces do not define variables
  • Interfaces do not define full function signatures due to Javascript's limitations, only function names
  • Interface supports multiple inheritance to other interfaces
  • Interface can not be instantiated
  • A class may implement multiple interfaces
  • A class implements an interface by defining a public virtual function, or a public pure virtual function with the same name as the name declared in the interface definition, and doing this for all functions declared in the interface definition.
  • Although virtual functions may have different accessors set going down the class extension chain, once a virtual function is required by an interface, pertaining classes in the class extension chain may only define said virtual function as public.
  • Class instances can not be cast to interfaces
  • Interfaces are still a type, and class instances can be checked against them