Question

Ruby modules make things like passing a database connection or other dependencies to various objects much easier while allowing for separation of concerns. Does Groovy support a similar functionality? And if so what is it called?

Était-ce utile?

La solution

In ruby modules are used either as mixins or to namespace a class (e.g. Net::HTTP).

To mixin the behavior you can use @mixin annotation. like examples here http://groovy.codehaus.org/Category+and+Mixin+transformations.

To namespace, groovy uses same mechanism as java i.e. using packages (e.g. groovy.sql.Sql).

I am not sure if that answered your question or not. But for dependency injection, while its common to do it mixin way in ruby (or even in scala/play), I have not seen it done a lot using @mixin in groovy. Usually a DI container like spring is used.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top