SMACS

Package smacs.util.listen

Interfaces for lambda objects.

See:
          Description

Interface Summary
GetName class has a getName method.
 

Package smacs.util.listen Description

Interfaces for lambda objects.

This subpackage contains only interface definitions. They are merily replacements for lambda objects which do not exist as such in the java language but must be emulated via instances of anonymous classes. To actually call the objects you need to have a declaration of the call synopsis somewhere - you can not just use `3 arguments`. Instead one has to have a synopsis with all types, even when they are just Object types, and that call synopsis must have been given a name.

So after all what we do here is create some hundreds of java files each having one interface definition and each having one function call synopsis. The name of the defined call synopsis should match the name of the interface class, i.e. an `interface NewNode` has a callable of `newNode(...)`.

And remember, better use extra specific interfaces/callable names, e.g not just `NewNode(...)` but `NewSimpleNode(...)`, and in your actual service object class just do a mapping of the call name as `newSimpleNode(...) return newNode(...)`. Remember that the righthand `newNode(..)` is polymorphic and any subclass overrideing `newNode(...)` will effectivly also override the functionality of `newSimpleNode(...)` and effectivly override any of its calls over the interface references of type `interface NewSimpleNode`.

To point it out explicitly, java does not have a means to call an object directly, i.e just doing somewhere a

{
   NewSimpleNode newSimpleNode = new NewSimpleNode() {...};
   SimpleNode node = newSimpleNode(); // impossible
}
Instead you will be calling the name of the embedded call synopsis on the lambda object, so the javaish way of doing it goes like this:
{
   static NewSimpleNode NewSimpleNodeDef = new NewSimpleNode() {
             SimpleNode newSimpleNode() {...}};
   SimpleNode node = NewSimpleNodeDef.newSimpleNode();
}

The advantage is that you can use the callable object and hand it around to other places - you can merily assign callable objects to variable references. In a lot of places you can avoid to subclass in order to redefine some minor functionality - and in the course creating possibly hundreds of public classes and java files.

The other end would have been to put in a public data member that one can initialize accordingly for the object and thereby modifying the functionality. But it pure object orientism better use a callable thing. And sadly, we have to simulate callable objects in java.

Of course one could be using java reflections to do the actuall call but that is a lot more nasty. Instead we can be tricky with the interfaces - e.g. we have class smacs.tree.SimpleNode implements smacs.util.listen.GetName {} and we can make assign a SimpleNode to a callable object somewhere that only ever needs getName() - but we do not need to put an assertion of SimpleNode there.

Per convention, static callable objects are named with an uppercase start thereby giving the impression on first read that they are an embedded class. In the example above DefNewSimpleNode could have been an inner class with a method named newSimpleNode(). If you think about it a minute then you will notice that an inner class definition is in fact identical to having an embedded static callable object.


SMACS