Let us get started with a simple example of a web application based on the nice Spark micro-framework.
Spark requires route handlers to extend an abstract base class called spark.Route
. The following
code snippet does just that:
module sparky import spark import spark.Spark function main = |args| { let conf = map[ # (1) ["extends", "spark.Route"], # (2) ["implements", map[ # (3) ["handle", |this, request, response| { # (4) return "Golo, world!" }] ]] ] let fabric = AdapterFabric() # (5) let routeMaker = fabric: maker(conf) # (6) let route = routeMaker: newInstance("/hello") # (7) get(route) # (8) }
An adapter configuration is provided by a map object. | |
The | |
The | |
The implementation is given by a closure whose signature matches the parent class definition, and where the first argument is the receiver object that is going to be the adapter instance. | |
An adapter fabric provides context for creating adapters. It manages its own class loader. | |
An adapter maker creates instances based on a configuration. | |
The | |
The |
Adapter objects implement the gololang.GoloAdapter
marker interface, so you can do type
checks on them a in: (foo oftype gololang.GoloAdapter.class)
.