I’d like to ask for the addition of an “onMissingMethod” event handler.
If you call a method on a class and it doesn’t exist - it looks for a method called “onMissingMethod()” - within the target class.
I have used it before (in ColdFusion) as a proxy, in a database class, where the application had a “service” layer (the public API) and a gateway / DAO which was private.
There is some convention at play with my example, CLASS_service.scala and CLASS_dao.scala.
CLASS_service.scala is the public API - but the method signature NEARLY ALWAYS matches the DAO’s - so it ends up being a lot if duplicate / boiler plate code.
At its simplest - the CLASS_service.scala ONLY has onMIssingMethod defined,
This takes the method name and the arguments (of the missing method, just called), as default arguments.
And I use it to proxy the original method call through CLASS_dao.OrigMethodName(OrigArguments),
(in my example use-case) CLASS_dao is dynamically produced by the name of the CLASS_service originally called : matching on CLASS_ as “my” convention.
Ultimately, meaning I don’t have to code the public API, just to fulfill the application design.
It can be used for all sorts of things, logging / error- handling / common code from multiple places - though I’ve only used it as a proxy.