Grails Packaging Structure

I am compiling the existing Groovy and Grails code base, but the package structure seems very strange to me.

For a domain class, they put it in the next package com.company.domain, then for the controller of this class it is com.company.controller

This structure seems very unpleasant to me, because the domain and controller classes are already organized under their own folders in the grails-app folder.

My plan is to remake packages and group based on actual usage, for example com.company.billing and com.company.util.

Are there any flaws in my plan? Is there anything good in the current package structure that I am missing?

+7
source share
1 answer

I think package names should separate code related to different business aspects. E.g. shopping site, I would recommend:

  • com.mycompany.myfancywebsite.product all materials related to the product (for example, the product domain class, ProductDetailController, etc.).
  • com.mycompany.myfancywebsite.cart for all products related to the basket (e.g. CartController, ShippingCostCalculationService, etc.).
  • com.mycompany.myfancywebsite.payment for all things related to payment.

IMHO it makes no sense to use package names to distinguish between the "type" of code (for example, domain, controller, service ...), it just does not add any value to it.

I would also recommend using util carefully in package names, this may be a sign that your code is not concentrated enough.

Read more in the wonderful book, Clean Code. Also see http://weblog.dangertree.net/2008/11/22/grails-package-naming/

+10
source

All Articles