Answer the question
In order to leave comments, you need to log in
How to correctly implement multiple object checks?
Good afternoon.
I have a design question. I have a fairly large object. I need to put this object through a lot of checks. There are 20+ such checks.
Now I have implemented the following scheme - There are 20+ check classes that extend one interface in which the check () and insert () methods are registered. In init() I create all these check classes and call the check() method on each one.
This is most likely the wrong approach. I would like to see some best practices for solving such a problem.
Answer the question
In order to leave comments, you need to log in
In the topic there is no problem as such. Checks can be done in different ways. But the main metric is likely to be the compactness of the code and the speed of making changes to it. From best practices. Start an auxiliary class. helper. And you make 20+ methods.
depending on what type of check is needed - all cases or up to the first unsuccessful
one, for the first one, you can offer a Builder that collects all the necessary check classes and only one fun check(): Result method looks outside
for the second, almost the same builder but with the fun next(): Result method and while not null e.g. checks have ended (or until an error occurs in Result)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question