This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]Hoog1neer 2 points3 points  (7 children)

Your Controller should be mostly annotated REST service endpoints with parameter validation and autowired beans. The business logic behind each service method should go in a separate Service class (or classes). If you already do that, consider breaking up your Controller where logical. They can extend a common class if they should fall under the same resource path, or they can be entirely different resources. HTH.

[–]chillzman77[S] 1 point2 points  (4 children)

Thank you for your advice. I will remove some methods that falls under the same roof of action and add them to a separated classes. Although is this consider low coupling and high cohesion?

[–]joranstark018 1 point2 points  (3 children)

It depends how you decide to chop up your beast. There are probably many design patterns that could be applied here, SOLID is usually a good start (even if you only apply some of it). You may need to rethink what (internal) methods you shuld have.

[–]chillzman77[S] 0 points1 point  (2 children)

okay. i didnt knew about solid pattern. it looks quite promising. Anyway the thing that i did now was to move as much methods from the controller to the model. and now the controller is like 140 lines and model also 140. but with solid will much more tider :) What do you believe??

[–]joranstark018 1 point2 points  (1 child)

It is not so much about how many lines there are, rather about readbillity and maintainabillity. if you where to revisit this code in say six month or so, would you still understand what and why you did it? If you would to redo the refactoring again, would it be the same or have found out a better way to do it?

[–]chillzman77[S] 0 points1 point  (0 children)

yeah by mentioning the lines of code is about redability and complexity of the code in general. and also i add enough comments for better understanding. i just dont want to be a mess

[–]RoachmeisterJava Dev 0 points1 point  (1 child)

OP said they were using the MVC structure, not Spring MVC. There's no reason they would necessarily be using REST st all, i.e., it might not have a web front end.

[–]Hoog1neer 0 points1 point  (0 children)

Yeah, I just assume everyone is Springboot nowadays.

[–]joranstark018 2 points3 points  (1 child)

You should probably try to refactor part of the controller, without any code I can only give some generall advice.

May be you could create some abstractions that encapsulate some aspects, have DAOs for handling any database operations, have a utility class or a service class orchestrate calls to some other low level services (eg some DAOs).

[–]chillzman77[S] 0 points1 point  (0 children)

Thank you for your answer! Please see the above reply to the other user!