Frameworks and Packages
Interfaces are often fundamental components of frameworks. In JADE, you can implement a framework: inline (that is, in a schema hierarchy) or as a package.
The following discussion applies to those implementations.
Frameworks usually require that client-supplied objects respond to some specific methods, which are known as callback methods. Most frameworks are written as generalized as possible, so that they can be utilized in a large number of situations. When you write a framework, you do not yet know the specific classes of the objects with which it will be working but that interaction with client-supplied code should occur according to your intentions.
To define the collaboration with the eventual code that will interact with the framework, you can use the following approaches.
-
Use a very general method that is defined in a class that the framework assumes its clients know about. In a very generic framework, this class ends up being the Object class.
-
Define an interface with the required methods and leave it to the users of the framework to implement it with the class or classes that are most convenient for them; that is, users will publish aspects of object collaboration without revealing its actual class.
The second of these approaches is the best in terms of flexibility and readability, and it allows for more-specific checks at compile time.