Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdapterInterface causes code duplication problems. #24

Closed
cyberail opened this issue Nov 18, 2020 · 0 comments
Closed

AdapterInterface causes code duplication problems. #24

cyberail opened this issue Nov 18, 2020 · 0 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request medium priority Issue has medium priority
Milestone

Comments

@cyberail
Copy link
Collaborator

Problem begins from the, RequestHandler's reply function:
RequestHandler's reply method was returning only DioAdapter which caused chaining problems for DioInterceptor, because DioInterceptor itself needs DioInterceptor to be returned from reply to chain methods and track the History.

So we needed to distinguish returns inside the reply function, this problem was going to be solved with creating generic type parameter for RequestHandler class, but while doing this another problem occurred: reply function was not able to understand what type it was returning(DioAdapter or DioInterceptor).

For the above mentioned problem two ways of the solution were suggested to solve it.

First, define an abstract interface AdapterInterface for both, DioInterceptor and DioAdapter, also we need to define all the methods(onGet , onPost......) inside the interface and those methods will be overriden from mixin RequestRouted.
In this way reply function return type is AdapterInterface and also reply function maintains it's code completion ability when you are creating chains, But there is big problem of code management because interface defines all of the methods from ReqeustRouted with their parameters , if we have to change parameters' types or quantities of all of the methods(onGet,onPost......) inside the RequestRouted mixin we will have to change everything inside interface too.

Second, reply functions return type will be T and it will return DioAdapter or DioInterceptor with following manner: return DioAdapter() as T or return DioInterceptor() as T, In this case there is no need for separate interface but this type of solution destroyed auto completion ability for reply() method while creating chains.

For now, wile prioritizing auto completion, First method was left for use, But we are looking for other ways of solution and open to suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request medium priority Issue has medium priority
Projects
None yet
Development

No branches or pull requests

5 participants