提煉接口重構是從一個已存在的類中提煉接口,它可以從某個類中選擇方法,把選中的方法提取到一個單獨的接口中.
更多實用技巧請查看《AndroidStudio實用指南》
操作步驟:
➤ 菜單欄: Refactor —> Extract —> Interface …
實例演示:
第1步: 光標放在某個類的任意位置 —> 執行菜單欄: Refactor —> Extract —> Interface … —> 彈出配置對話框
第2步: 輸入接口名爲IContentItem, 選中方法getContentUri()和getShareIntent(context:Context),提其提煉到接口中—> 執行重構
更多實用技巧請查看《AndroidStudio實用指南》
提取的接口如下:
/**
* Created by bixiaopeng on 16/1/3.
*/
public interface IContentItem {
Uri getContentUri();
Intent getShareIntent(Context context);
}
原來的類實現了這個接口:
public class ContentItem implements IContentItem {
...
}
更多實用技巧請查看《AndroidStudio實用指南》
作者: 老畢
微信公衆帳號: wirelessqa