I have some experience with Django and its MVC (MTV rather...) concept. In my previous project in django, I always tried pack a lot of functions (methods) to Model class - all which could work on single entity in Model object. I know that in Java EE world, there is much more layers than 3, so how should I do it in Spring? For instance, where should I place function which sum up few properties of entity? Anyway, do models in spring are also called "model"?
Just apply good OO practices. If some behavior can be encapsulated in the Model class, then definitely put it in the Model class. For example, a Model having a salary and a bonus properties might of course have a getTotalIncome method which returns the sum of salary and bonus.
Of course, it shouldn't cross its own boudaries. If the computation of the total income necessitates the call of a service to apply some tax based on the current month and some configuration in the database, this becomes business logic and couples your model objet with the service layer, which should not be done. So the getTotalIncome method in this case should not exist anymore.
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