The Lucy backend (ILcyLucyEnv
) provides a mechanism for sharing objects between different
parts of Lucy without creating a hard dependency between those parts.
This mechanism is called the service mechanism.
You can see it as a giant bag: you can put objects in the bag with
ILcyLucyEnv#addService(Object)
,
and remove them from the bag with ILcyLucyEnv#removeService(Object)
.
It is also possible to request from the bag all objects that extend or implement a certain class or interface.
An example use case of why it is important to have such a mechanism involves the Lucy map add-on: the map add-on has an action to load data on the map, which needs to support a lot of data formats. Loading data on the map requires model decoders and layer factories. You can make those model decoders and layer factories available as services. By letting the loading action delegate to the model decoder and layer factory services, the action can support all data formats. You can add support for an extra data format without changing any action code, by adding new model decoders and layer factories to the services.
In this scenario, the data format add-ons are the suppliers of the services, and the open action of the map add-on a consumer of those services.