Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put service classes in Play Framework?

In Grails we have service classes that contain business logic that is called from controllers. Where do I put service classes in Play Framework project? And if I define methods in controller that are not request actions but utility methods such as int findMax(int a, int b) in controller, is this possible to define within the controller and how do I declare such methods?

like image 454
ace Avatar asked Jun 09 '11 21:06

ace


2 Answers

Business logic in general should be implemented as methods on the model classes, either statically or not, depending on the context.

While there are no rules about this, utility methods should either go in their own utility class in a package, or can be part of model classes depending on the context.

As an example, a simple utility method that compares two primitives, such as your findMax(int, int) class, is better off in a utility class, though a method such as findOldest(Person, Person) is better suited to being a static method on the Person model class.

like image 151
Rich Avatar answered Nov 14 '22 22:11

Rich


There are no rules for this. I personally would put utility-methods in utility-classes. Utility-classes and service-classes should follow the normal package-rules, i.e. com.stackoverflow.services.statistic.UsageCalculator.

like image 2
niels Avatar answered Nov 14 '22 23:11

niels