How to separate interface from implementation in Grails services?

前端 未结 4 1891
鱼传尺愫
鱼传尺愫 2021-02-04 05:15

I was wondering if it\'s possible to create a service interface on Grails and I can\'t find a proper way of doing it. This explanation isn\'t satisfactory, since it seems to mix

4条回答
  •  一个人的身影
    2021-02-04 05:55

    Its not a design flaw. Groovy is different than java in that it is a dynamic language that uses 'duck-typing'. Whats interesting in groovy is that there are also interfaces. So if you follow @don's suggestion, you can make sure that your service conforms to the interface, but the way you do DI with grails is to just specify the service implementation. i.e. you do not get the compile time check where you use the service implementation, like you do in java.

    Note that there is no tight coupling here. Coupling implies that something is bound to a type. But with groovy's loose typing system, types are essentially dynamic creatures. So in java, if you declare a type to be a specific implementation, the code might not compile if you change the type later. In groovy, the code will always compile if you use the 'def'...(I think this is correct)

提交回复
热议问题