views:

521

answers:

1

Hi,

This is a design question : when do I need to create/use a static method (in a domain class for instance) and when do I need to create/use a service instead? What is the difference between them ?

Thank you.

A: 

If the method is to do only with the behaviour/details of the domain class then I'd make it a method on the domain (not necessarlily a static one). If it is more related to business logic then I'd put it in a service.

cheers

Lee

leebutts
Hi,I have a method that builds dynamically a google chart URL out of a DB request related to one domain. So, in that case what kind of method (service, static method of the domain class, helper method in the view...) would you have created ?
fabien7474
create a service. Static methods are harder to mock out. And eventually, if you want to have transactions, its easier to do it in a service.
Chii
Thx...but how can I access this service method from a view (for a domain static method, it is ok) ? When declaring `def helpersService`, it doesn't work.
fabien7474
It sounds like you should use a tagLib that gets injected with your service.
leebutts