Grails Package Structure

后端 未结 1 1869
死守一世寂寞
死守一世寂寞 2020-12-18 00:04

I am picking up an existing codebase that is Groovy and Grails, but the package structure seems very odd to me.

For a domain class they put it in the following packa

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 00:11

    I think package names should separate code belonging to different business aspects. For e.g. a shopping website, I'd recommend:

    • com.mycompany.myfancywebsite.product to all product related stuff (e.g. Product domain class, ProductDetailController etc.)
    • com.mycompany.myfancywebsite.cart to all shopping cart related stuff (e.g. CartController, ShippingCostCalculationService etc.)
    • com.mycompany.myfancywebsite.payment to all payment related things

    IMHO it does not make sense to use package names to distinguish the "type" of code (e.g. domain, controller, service...), this simply adds no value to it.

    I'd also recommend carefully using util in package names, this might be a sign that your code is not focussed enought.

    For further reading, see the excellent book "Clean code". Also see http://weblog.dangertree.net/2008/11/22/grails-package-naming/

    0 讨论(0)
提交回复
热议问题