Retrofit封装Okhttp逻辑原理
2021-03-06 本文已影响0人
flynnny
总结自https://www.bilibili.com/video/BV1To4y1o7Eb
retrofit封装了Okhttp 本身并不能进行网络请求。只能在Android使用的网络请求框架。


request:统一完成(post/get/...)
回调陷阱:完成上一步网络请求才能进行下一步网络请求。

Retrofit简化了网络请求。优化了网络请求的使用。



build设计模式:参数》5个;存在可选参数。
retrofit.java这里使用的设计模式:
外观、门面模式:本生并不具备什么功能,封装了网络请求的接口。

Retrofit的create为什么用动态代理?


这行代码是Retrofit的核心,返回了一个对象。
等于new 了一个ISaredListService()对象
动态代理。

1.对接口了进行拦截。获取到所有的注解信息,即是构建request动态变化的对象
2.就可以动态构建带着具体请求的url。
3.解决了构建url繁琐的问题。

serviceMethod设计理念

loadServiceMethod方法包含大量反射、大量解析。
所以设计了一个存放serviceMethod的缓存



每一个接口都有一个对应的serviceMethod。
