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”?
I have some experience with Django and its MVC (MTV rather…) concept. In my
Share
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
salaryand abonusproperties might of course have agetTotalIncomemethod 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
getTotalIncomemethod in this case should not exist anymore.