Grails包装结构 [英] Grails Package Structure
问题描述
对于一个领域类,他们把它放在了下面的包com.company.domain,然后为该类的控制器,它是com.company.controller
该结构似乎非常对我来说,因为域和控制器类是已经在grails-app文件夹中的自己的文件夹下进行了组织。
我的计划是基于实际使用重做包和组,例如com.company.billing和com .company.util。
我的计划有什么缺点吗?
我认为软件包名称应该区分属于不同的代码业务方面。对于例如一个购物网站,我建议:
com.mycompany.myfancywebsite.product
所有与产品相关的东西(例如Product domain class,ProductDetailController等)
com.mycompany.myfancywebsite.cart
购物车相关的东西(例如CartController,ShippingCostCalculationService等)
com.mycompany.myfancywebsite.payment
>
恕我直言,使用包名来区分代码的类型(例如域,控制器,服务...)是没有意义的,这只是增加了它的价值。
我还建议在包名中小心使用 util
,这可能会表明你的代码不够集中。
如需进一步阅读,请参阅优秀书籍清洁代码。另请参阅 http://weblog.dangertree.net/2008/11/ 22 / grails-package-naming /
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 package com.company.domain then for the controller of that class it is com.company.controller
That structure seems very off to me since the domain and controller classes are already organized under their own folders in the grails-app folder.
My plan is to redo the packages and group based on actual use such as com.company.billing and com.company.util .
Are there any disadvantages to my plan? Is there anything good about the current package structure that I'm missing?
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/
这篇关于Grails包装结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!