views:

161

answers:

3

How come it is good practice within Grails to place classes in packages (e.g. mycompany.Book)?

I know it is a prerequisite in order to deploy Grails solution to the Google App Engine (using the plugin), but other than that and a well structured code library for large projects, what other benefits are there in describing packages for classes within Grails?

+1  A: 

Grails runs on Groovy, which has a strong heritage with Java. Java encourages packages for well-documented reasons and Groovy/Grails follows suit. I think the main benefit stems from your description: a well-structured code library for large projects.

Michael Easter
+2  A: 

Another good reason, as mentioned by Marcel Overdijk in this blog post, is if domain classes has the same name as classes within Groovy, it is not possible to distinguish the two.

PropellerHead
+1  A: 

The most valuable reason that I've seen, is that you cannot "import" classes without a package into a class that DOES have a package. that means that you can't access any domain/service/controller/etc classes that don't have packages from your utility code that you might put a package on.

Ted Naleid