Answer the question
In order to leave comments, you need to log in
How should classes interact with each other?
There is a Service class that makes HTTP requests.
There is also a Pagination class that sets up pagination options for queries.
The last class is the Filter class, which has its own fields that should be part of the request.
Should I create a ConfigRequest class that depends on the pagination class and the filter class and the rest.
I wonder what the relationship should be between the classes to set the http options for the service where the get method is located.
Thanks a lot!
Answer the question
In order to leave comments, you need to log in
I somewhat agree with Robur - this class scheme is more reminiscent of a cargo cult, the classes are made according to the "Schaub Bulo" principle. "Everyone has relationships and I will!"
Just the name "Service class that makes HTTP requests" makes you want to shoot yourself. HOW, how is it even possible to name a class that makes HTTP requests (and, as I suspect, not any at all, but quite specific ones), with the word Service ? What should be in the head of a person who, I don’t know, calls a glass for kefir the word “Thing”?
But I do not agree with his categorical conclusion. For practice in OOP and for better structuring of the code, it is possible and necessary to break it into classes. But this must be done wisely, and not stupidly mechanically cutting off a random piece of code into a separate class.
Therefore, to begin with, make two classes: a class, damn it, HTTPRequest, which performs HTTP requests , and a class for your requests to a specific service - with pagination, flagellation and what else you have. With a name by which you can understand what he does. Then look at this class, which of its methods turned out to be very bloated, and think about which of them can be moved into separate classes.
To make http requests with filters and pagination, you only need one Service class. Sometimes you can do with one function.
Why do you need all this, have you read a book on Java?
If all this is born from specific conditions and requirements and this is a reasonable complexity - write all this in the question.
If it just seems to you that it’s right because you know about SOLID, patterns and OOP, then it’s not worth it, any tool is needed where it is needed, effective and improves the result or the process of obtaining it and not where it’s abstract “it will be more correct”.
There is no single correct solution as in mathematics. In fact, if you take 10 developers who know solid, then they will all give out 10 different solutions to this problem, and everyone will be right, because OOP practices and solid are just recommendations.
Write the source code of Service as a single class, publish it here and listen to suggestions for improvement.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question