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?
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With