In this (well worded question) I'm reading 2 distinct sub-questions:
- Is it okay to use static methods to declare BedSheet routes?
- Is it okay to create Route facets for BedSheet?
The common theme between the two questions is on-going clarity and maintenance. This can be quite a personal 'thing' and, like the proverbial cat, there is more than one way to skin it.
Anyhow, to address them individually:
Q). Is it okay to use static methods to declare BedSheet routes?
A). Yes, it is fine (but read on...)
Q). Is it okay to create Route facets for BedSheet?
A). In short, yes. In long...
As this (paraphrased) question implies - neither BedSheet nor IoC have any facets for declaring services or route handler methods. This is largely because it is not felt that such facets and associated services are 'core' enough to be included in the frameworks.
Keeping the configuration of routes and services in an AppModule
means it is easy to find and keep track of - especially for newcomers to the code base.
On larger projects, a de-centralised configuration through facets can cause minor maintenance headaches. For if using facets, the only way to discover what services you have is through a textual search. The same applies to routes. A new comer trying to make sense of the project would have to wade through various pages of search results. Whereas a mere glance at an AppModule
would herald the same understanding.
The word can is deliberately chosen because with enough coding diligence, be it class naming or directory structure, services and routes become logically grouped and are easy to find.
The Tales Framework has facets for declaring routes, but has this to say about them in Externalising Routes:
Defining routes along with methods as facets is cool and quick, but it has the following disadvantages:
- Does not clearly define the order in which routes will be picked up
- You cannot see all the routes that your app defines in one place.
So declaring services and routes with facets is not bad, just be wary of it. That said, I've been thinking about implementing a REST API based on facets, similar to JAX-RS (Java API for RESTful Services)!
As an aside, facet configuration is trivial to implement; for example if you had a facet called @Service
that you placed on IoC service classes (or mixins) then you could just add the following line to your bind method:
const class AppModule {
static Void bind(ServiceBinder binder) {
AppModule#.pod.types .findAll { it.hasFacet(Service#) }.each { binder.bind(it) }
}
}
To sum up:
If you are to be solely responsible for a code base, or are working on a smaller project, then using facets is fine. If maintenance is to shared by others, or if the project is non-trivial, then I'd consider keeping the configuration in either a single AppModule
, or in multiple modules as defined by the @SubModule facet.