In Crystal 1.5, Warn on positional parameter mismatches for abstract def implementations by HertzDevil · Pull Request #11915 · crystal-lang/crystal · GitHub “Warn on positional parameter mismatches for abstract def implementations” means this technique will probably be difficult to implement as I’ve represented it here because not only the method names but also the parameter names will have to be in sync across various implementing libraries. I find that unlikely even in the most rigorous specifications.
I don’t think it’s a deal-breaker though. The same pattern can be used this way:
module Library::GaskinsRedisInterface
abstract def expire(key, seconds)
# code from Library will call this method:
# - interactions of types can be cleanly isolated here
# - eventually this will delegate to the abstract def above
def library_expire(key, seconds)
expire key, seconds
end
end
It’s laborious at best, but it’s workable. It provides a place for an adapter pattern if the interfaces are disparate enough as well.