Answer the question
In order to leave comments, you need to log in
What is the best way to remove code repetition?
Oop geniuses, tell me how best to get rid of repeated pieces of code in methods, the methods are different, they return different information, but the point is that you have to write the same piece every time
if (mGetRequest != null && mGetRequest.isExecuting())
return;
ParamsBuilder paramsBuilder = new ParamsBuilder();
paramsBuilder.setMethod(BOOKS_METHOD);
paramsBuilder.setEnumParse(EnumParse.BOOKS);
if (page != null) paramsBuilder.addParams("page", String.valueOf(page));
if (search != null) paramsBuilder.addParams("s", search);
if (userId != null) paramsBuilder.addParams("uid", userId.toString());
mGetRequest = new HttpRequest(listener);
mGetRequest.execute(paramsBuilder);
Answer the question
In order to leave comments, you need to log in
A method that takes a functional interface (a lambda with code) as input, a condition is checked inside the method, and depending on the condition, the lambda is executed or not.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question