Grails Package Structure
-
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?
-
Answer:
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/
Jeff Beck at Stack Overflow Visit the source
Related Q & A:
- What is this structure called?Best solution by Programmers
- What is a good way to structure mark-up generating code and avoid the example mess?Best solution by Code Review
- How would I structure database the best?Best solution by Stack Overflow
- How to Convert a C++ Structure into C# Structure?Best solution by Stack Overflow
- How to solve Repeated column in Grails mapping for entity?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.