EventBus源碼分析

簡(jiǎn)介

源碼基于 org.greenrobot:eventbus:3.2.0
EventBus是Android和Java的發(fā)布/訂閱事件總線永毅。

使用步驟

  1. 自定義消息
public static class MessageEvent { 
    //可以根據(jù)業(yè)務(wù)需求添加所需的字段
    public int code;//定義一個(gè)業(yè)務(wù)code,可區(qū)分不同消息
}
  1. 聲明并注解訂閱方法蛾默,可以指定運(yùn)行線程
@Subscribe(threadMode = ThreadMode.MAIN)  //ThreadMode.MAIN指定在主線程運(yùn)行
public void onMessageEvent(MessageEvent event) {
    //獲取到MessageEvent消息體后贴见,可在這進(jìn)行業(yè)務(wù)處理
};
  1. 在Activity生命周期注冊(cè)和反注冊(cè)EventBus
 @Override
 public void onStart() {
     super.onStart();
    //注冊(cè)
     EventBus.getDefault().register(this);
 }

 @Override
 public void onStop() {
     super.onStop();
    //反注冊(cè)
     EventBus.getDefault().unregister(this);
 }
  1. 準(zhǔn)備完畢后锦庸,就可以開(kāi)始發(fā)送一個(gè)自定義消息MessageEvent
//可以在主線程也可在非主線程進(jìn)行發(fā)送
EventBus.getDefault().post(new MessageEvent());

以上就是EventBus的簡(jiǎn)單使用,下面來(lái)分析一下EventBus告唆,自定義消息如何發(fā)送到指定方法上去并且在是如何指定運(yùn)行線程巴帮。

原理分析(圖片)

準(zhǔn)備分析前,先通過(guò)圖來(lái)簡(jiǎn)單說(shuō)明一下大致流程

  1. 剛開(kāi)始瞬女,我們未訂閱任何方法和未發(fā)送任何消息事件
image.png
  1. 假設(shè)在EventActivity訂閱一個(gè)onMessageEvent方法窍帝,并且該方法接收MessageEvent消息事件,剛開(kāi)始相互沒(méi)有關(guān)聯(lián)


    image.png
  2. 當(dāng)Activity調(diào)用onStart時(shí)候诽偷,EventBus進(jìn)行了注冊(cè)坤学,這個(gè)時(shí)候就開(kāi)始關(guān)聯(lián)起來(lái)疯坤,

 @Override
 public void onStart() {
     super.onStart();
    //注冊(cè)
     EventBus.getDefault().register(this);
 }
image.png

相應(yīng)的,當(dāng)反注冊(cè)的時(shí)候拥峦,將移除對(duì)應(yīng)關(guān)系

  1. 發(fā)送消息事件


    image.png

原理分析(源代碼)

EventBus使用了單利模式贴膘,所以全局只有一個(gè)EventBus實(shí)例卖子,使用DLC

    public static EventBus getDefault() {
        EventBus instance = defaultInstance;
        if (instance == null) {
            synchronized (EventBus.class) {
                instance = EventBus.defaultInstance;
                if (instance == null) {
                    instance = EventBus.defaultInstance = new EventBus();
                }
            }
        }
        return instance;
    }

在開(kāi)始分析前略号,先了解EventBus里面2個(gè)字段,都是Map+List的數(shù)據(jù)格式
第一個(gè)是存放一個(gè)消息類型對(duì)應(yīng)的全部訂閱方法
第二個(gè)是存放和注冊(cè)對(duì)象有關(guān)聯(lián)的消息類型

  //根據(jù)消息事件類型進(jìn)行存儲(chǔ)所有訂閱方法
  private final Map<Class<?>, CopyOnWriteArrayList<Subscription>> subscriptionsByEventType;
  //根據(jù)注冊(cè)的實(shí)例存儲(chǔ)當(dāng)前對(duì)象訂閱方法所有接收消息事件
  private final Map<Object, List<Class<?>>> typesBySubscriber;

以我們前面使用步驟代碼為例洋闽,假設(shè)當(dāng)前代碼在EventActivity

class EventActivity{
    //消息
    public static class MessageEvent { }

    //訂閱方法
    @Subscribe(threadMode = ThreadMode.MAIN)  //ThreadMode.MAIN指定在主線程運(yùn)行
    public void onMessageEvent(MessageEvent event) { };

    @Override
    public void onStart() {
      super.onStart();
       EventBus.getDefault().register(this);
    }

    @Override
    public void onStop() {
       super.onStop();
       EventBus.getDefault().unregister(this);
    }
}

通過(guò)注冊(cè)進(jìn)行關(guān)聯(lián)

public void register(Object subscriber) {
    //獲取注冊(cè)對(duì)象的類類型玄柠,這里是EventActivity.class
    Class<?> subscriberClass = subscriber.getClass();
    //根據(jù)注解獲取EventActivity所有訂閱方法,并且封裝為SubscriberMethod對(duì)象诫舅,因?yàn)锳ctivity可以訂閱多個(gè)方法羽利,
    //所以最終返回的是一個(gè)數(shù)組
    List<SubscriberMethod> subscriberMethods = subscriberMethodFinder.findSubscriberMethods(subscriberClass);
    synchronized (this) {
        //遍歷所有訂閱方法,將訂閱方法存放到指定的位置
        for (SubscriberMethod subscriberMethod : subscriberMethods) {
            //訂閱
            subscribe(subscriber, subscriberMethod);
        }
    }
}
圖示返回3個(gè)SubscriberMethod刊懈,比較好表示為數(shù)組这弧,實(shí)際應(yīng)該返回1個(gè)

接下來(lái)繼續(xù)看如何進(jìn)行訂閱

//訂閱
//Object subscriber這里為EventActivty對(duì)象
private void subscribe(Object subscriber, SubscriberMethod subscriberMethod) {
    //獲取訂閱方法接收的消息類型,這里為MessageEvent.class
    Class<?> eventType = subscriberMethod.eventType;
    //將EventActivity對(duì)象和訂閱方法組合為Subscription
    Subscription newSubscription = new Subscription(subscriber, subscriberMethod);
    //根據(jù)消息類型獲取該消息存放訂閱方法的數(shù)組
    CopyOnWriteArrayList<Subscription> subscriptions = subscriptionsByEventType.get(eventType);
    if (subscriptions == null) {
        //為空虚汛,也就是該消息第一次訂閱匾浪,則創(chuàng)建一個(gè)新的數(shù)組,并且添加到map中
        subscriptions = new CopyOnWriteArrayList<>();
        subscriptionsByEventType.put(eventType, subscriptions);
    } else {
        //同一個(gè)訂閱方法不能重復(fù)訂閱
        if (subscriptions.contains(newSubscription)) {
            throw new EventBusException("Subscriber " + subscriber.getClass() + " already registered to event "
                    + eventType);
        }
    }
    //這里主要是根據(jù)優(yōu)先級(jí)將訂閱方法插入指定位置
    int size = subscriptions.size();
    for (int i = 0; i <= size; i++) {
        if (i == size || subscriberMethod.priority > subscriptions.get(i).subscriberMethod.priority) {
            //將訂閱方法插入數(shù)組卷哩,這樣就完成一次訂閱方法的添加
            subscriptions.add(i, newSubscription);
            break;
        }
    }
    //獲取該對(duì)象(EventActivity)全部訂閱方法接收的消息事件
    List<Class<?>> subscribedEvents = typesBySubscriber.get(subscriber);
    if (subscribedEvents == null) {
        //第一次創(chuàng)建一個(gè)并且設(shè)置到map
        subscribedEvents = new ArrayList<>();
        typesBySubscriber.put(subscriber, subscribedEvents);
    }
    //添加消息類型
    subscribedEvents.add(eventType);
    ...
}
image.png

發(fā)送一個(gè)MessageEvent

public void post(Object event) {
    //獲取當(dāng)前線程的PostingThreadState
    PostingThreadState postingState = currentPostingThreadState.get();
    //獲取消息隊(duì)列
    List<Object> eventQueue = postingState.eventQueue;
    //將消息加入隊(duì)列
    eventQueue.add(event);
    if (!postingState.isPosting) {
        //如果空閑狀態(tài)蛋辈,則觸發(fā)進(jìn)行消息發(fā)送
        //獲取當(dāng)前線程是否主線程
        postingState.isMainThread = isMainThread();
        //標(biāo)記正在發(fā)送消息
        postingState.isPosting = true;
        if (postingState.canceled) {
            throw new EventBusException("Internal error. Abort state was not reset");
        }
        try {
            while (!eventQueue.isEmpty()) {
                //循環(huán)從隊(duì)列獲取消息,直到隊(duì)列為空
                postSingleEvent(eventQueue.remove(0), postingState);
            }
        } finally {
            //重置狀態(tài)
            postingState.isPosting = false;
            postingState.isMainThread = false;
        }
    }
}
private void postSingleEvent(Object event, PostingThreadState postingState) throws Error {
    //獲取當(dāng)前消息的類類型将谊,這里是MessagEvent.class
    Class<?> eventClass = event.getClass();
    //是否找到訂閱方法
    boolean subscriptionFound = false;
    if (eventInheritance) {
        //是否查詢MessagEvent.class的父類類型冷溶,也就是父類型的消息訂閱的方法也要進(jìn)行發(fā)送
        List<Class<?>> eventTypes = lookupAllEventTypes(eventClass);
        int countTypes = eventTypes.size();
        for (int h = 0; h < countTypes; h++) {
            Class<?> clazz = eventTypes.get(h);
            //發(fā)送消息
            subscriptionFound |= postSingleEventForEventType(event, postingState, clazz);
        }
    } else {
        //發(fā)送消息
        subscriptionFound = postSingleEventForEventType(event, postingState, eventClass);
    }
    if (!subscriptionFound) {
        //未找到訂閱方法進(jìn)行相應(yīng)處理
        if (logNoSubscriberMessages) {
            logger.log(Level.FINE, "No subscribers registered for event " + eventClass);
        }
        if (sendNoSubscriberEvent && eventClass != NoSubscriberEvent.class &&
                eventClass != SubscriberExceptionEvent.class) {
            post(new NoSubscriberEvent(this, event));
        }
    }
}
private boolean postSingleEventForEventType(Object event, PostingThreadState postingState, Class<?> eventClass) {
    //定義一個(gè)訂閱方法的數(shù)組
    CopyOnWriteArrayList<Subscription> subscriptions;
    synchronized (this) {
        //根據(jù)事件類型獲取全部訂閱方法的數(shù)組
        subscriptions = subscriptionsByEventType.get(eventClass);
    }
    //存在訂閱方法
    if (subscriptions != null && !subscriptions.isEmpty()) {
        //遍歷所有訂閱方法
        for (Subscription subscription : subscriptions) {
            //標(biāo)記當(dāng)前發(fā)送的事件和訂閱方法
            postingState.event = event;
            postingState.subscription = subscription;
            boolean aborted;
            try {
                //發(fā)送事件
                postToSubscription(subscription, event, postingState.isMainThread);
                aborted = postingState.canceled;
            } finally {
                //重置
                postingState.event = null;
                postingState.subscription = null;
                postingState.canceled = false;
            }
            if (aborted) {
                //如果中途中斷則跳出循環(huán)
                break;
            }
        }
        return true;
    }
    return false;
}
private void postToSubscription(Subscription subscription, Object event, boolean isMainThread) {
    switch (subscription.subscriberMethod.threadMode) {
        case POSTING://在哪個(gè)線程發(fā)送消息,就在哪個(gè)線程進(jìn)行接收處理
            invokeSubscriber(subscription, event);
            break;
        case MAIN://主線程接收處理
            if (isMainThread) {
                //當(dāng)前是主線程尊浓,直接發(fā)送
                invokeSubscriber(subscription, event);
            } else {
                //當(dāng)前非主線程逞频,則通過(guò)mainThreadPoster發(fā)送到主線程
                mainThreadPoster.enqueue(subscription, event);
            }
            break;
        case MAIN_ORDERED://主線程按順序接收處理
            if (mainThreadPoster != null) {
                mainThreadPoster.enqueue(subscription, event);
            } else {
                // temporary: technically not correct as poster not decoupled from subscriber
                invokeSubscriber(subscription, event);
            }
            break;
        case BACKGROUND:
            if (isMainThread) {
                backgroundPoster.enqueue(subscription, event);
            } else {
                invokeSubscriber(subscription, event);
            }
            break;
        case ASYNC:
            asyncPoster.enqueue(subscription, event);
            break;
        default:
            throw new IllegalStateException("Unknown thread mode: " + subscription.subscriberMethod.threadMode);
    }
}
void invokeSubscriber(Subscription subscription, Object event) {
    try {
        //通過(guò)反射調(diào)用訂閱方法,完成一次消息發(fā)送
        subscription.subscriberMethod.method.invoke(subscription.subscriber, event);
    } catch (InvocationTargetException e) {
        handleSubscriberException(subscription, event, e.getCause());
    } catch (IllegalAccessException e) {
        throw new IllegalStateException("Unexpected exception", e);
    }
}

子線程切換成主線程

//主線程HandlerPoster繼承自Handler
public class HandlerPoster extends Handler implements Poster {

    private final PendingPostQueue queue;
    private final int maxMillisInsideHandleMessage;
    private final EventBus eventBus;
    private boolean handlerActive;

    protected HandlerPoster(EventBus eventBus, Looper looper, int maxMillisInsideHandleMessage) {
        super(looper);
        this.eventBus = eventBus;
        this.maxMillisInsideHandleMessage = maxMillisInsideHandleMessage;
        queue = new PendingPostQueue();
    }

    public void enqueue(Subscription subscription, Object event) {
        //消息入隊(duì)
        PendingPost pendingPost = PendingPost.obtainPendingPost(subscription, event);
        synchronized (this) {
            queue.enqueue(pendingPost);
            if (!handlerActive) {
                handlerActive = true;
                //發(fā)送消息到主線程的Looper
                if (!sendMessage(obtainMessage())) {
                    throw new EventBusException("Could not send handler message");
                }
            }
        }
    }

    @Override
    public void handleMessage(Message msg) {
        //接收到消息處理栋齿,后面流程就是進(jìn)行反射調(diào)用訂閱方法
        //這樣就完成一次子線程到主線程的切換
        boolean rescheduled = false;
        try {
            long started = SystemClock.uptimeMillis();
            while (true) {
                PendingPost pendingPost = queue.poll();
                if (pendingPost == null) {
                    synchronized (this) {
                        // Check again, this time in synchronized
                        pendingPost = queue.poll();
                        if (pendingPost == null) {
                            handlerActive = false;
                            return;
                        }
                    }
                }
                //反射調(diào)用
                eventBus.invokeSubscriber(pendingPost);
                long timeInMethod = SystemClock.uptimeMillis() - started;
                if (timeInMethod >= maxMillisInsideHandleMessage) {
                    if (!sendMessage(obtainMessage())) {
                        throw new EventBusException("Could not send handler message");
                    }
                    rescheduled = true;
                    return;
                }
            }
        } finally {
            handlerActive = rescheduled;
        }
    }
}

主線程切換成子線程

final class BackgroundPoster implements Runnable, Poster {
    //隊(duì)列
    private final PendingPostQueue queue;
    private final EventBus eventBus;

    private volatile boolean executorRunning;

    BackgroundPoster(EventBus eventBus) {
        this.eventBus = eventBus;
        queue = new PendingPostQueue();
    }

    public void enqueue(Subscription subscription, Object event) {
        //消息入隊(duì)
        PendingPost pendingPost = PendingPost.obtainPendingPost(subscription, event);
        synchronized (this) {
            queue.enqueue(pendingPost);
            if (!executorRunning) {
                executorRunning = true;
                //通過(guò)EventBus的線程池執(zhí)行
                //這樣就完成一次主線程到子線程的切換
                eventBus.getExecutorService().execute(this);
            }
        }
    }

    @Override
    public void run() {
        try {
            try {
                while (true) {
                    PendingPost pendingPost = queue.poll(1000);
                    if (pendingPost == null) {
                        synchronized (this) {
                            // Check again, this time in synchronized
                            pendingPost = queue.poll();
                            if (pendingPost == null) {
                                executorRunning = false;
                                return;
                            }
                        }
                    }
                    //反射調(diào)用
                    eventBus.invokeSubscriber(pendingPost);
                }
            } catch (InterruptedException e) {
                eventBus.getLogger().log(Level.WARNING, Thread.currentThread().getName() + " was interruppted", e);
            }
        } finally {
            executorRunning = false;
        }
    }
}

最后看下反注冊(cè)如何處理

public synchronized void unregister(Object subscriber) {
    //根據(jù)注冊(cè)對(duì)象獲取消息事件類型數(shù)組
    List<Class<?>> subscribedTypes = typesBySubscriber.get(subscriber);
    if (subscribedTypes != null) {
        for (Class<?> eventType : subscribedTypes) {
            //循環(huán)消息類型數(shù)組
            unsubscribeByEventType(subscriber, eventType);
        }
        //移除該數(shù)組
        typesBySubscriber.remove(subscriber);
    } else {
        logger.log(Level.WARNING, "Subscriber to unregister was not registered before: " + subscriber.getClass());
    }
}
private void unsubscribeByEventType(Object subscriber, Class<?> eventType) {
    //根據(jù)消息事件類型獲取訂閱方法數(shù)組
    List<Subscription> subscriptions = subscriptionsByEventType.get(eventType);
    if (subscriptions != null) {
        int size = subscriptions.size();
        for (int i = 0; i < size; i++) {
            Subscription subscription = subscriptions.get(i);
            //判斷訂閱對(duì)象是否相同虏劲,相同則移除
            if (subscription.subscriber == subscriber) {
                subscription.active = false;
                subscriptions.remove(i);
                i--;
                size--;
            }
        }
    }
}

這樣就反注冊(cè)移除全部訂閱方法

總結(jié)

準(zhǔn)備階段
  1. 創(chuàng)建消息事件對(duì)象
  2. 添加一個(gè)訂閱方法并且添加注解
  3. 調(diào)用EventBus進(jìn)行注冊(cè)
發(fā)送階段
  1. 通過(guò)EventBus.post發(fā)送前面創(chuàng)建的消息事件對(duì)象
注銷階段
  1. 調(diào)用EventBus進(jìn)行注銷,清空之前訂閱的方法
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末褒颈,一起剝皮案震驚了整個(gè)濱河市柒巫,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌谷丸,老刑警劉巖堡掏,帶你破解...
    沈念sama閱讀 218,525評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異刨疼,居然都是意外死亡泉唁,警方通過(guò)查閱死者的電腦和手機(jī)鹅龄,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)亭畜,“玉大人扮休,你說(shuō)我怎么就攤上這事∷┩遥” “怎么了玷坠?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,862評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)劲藐。 經(jīng)常有香客問(wèn)我八堡,道長(zhǎng),這世上最難降的妖魔是什么聘芜? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,728評(píng)論 1 294
  • 正文 為了忘掉前任兄渺,我火速辦了婚禮,結(jié)果婚禮上汰现,老公的妹妹穿的比我還像新娘挂谍。我一直安慰自己,他們只是感情好瞎饲,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,743評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布口叙。 她就那樣靜靜地躺著,像睡著了一般企软。 火紅的嫁衣襯著肌膚如雪庐扫。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,590評(píng)論 1 305
  • 那天仗哨,我揣著相機(jī)與錄音形庭,去河邊找鬼。 笑死厌漂,一個(gè)胖子當(dāng)著我的面吹牛萨醒,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播苇倡,決...
    沈念sama閱讀 40,330評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼富纸,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了旨椒?” 一聲冷哼從身側(cè)響起晓褪,我...
    開(kāi)封第一講書(shū)人閱讀 39,244評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎综慎,沒(méi)想到半個(gè)月后涣仿,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,693評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,885評(píng)論 3 336
  • 正文 我和宋清朗相戀三年好港,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了愉镰。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,001評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡钧汹,死狀恐怖丈探,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情拔莱,我是刑警寧澤碗降,帶...
    沈念sama閱讀 35,723評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站辨宠,受9級(jí)特大地震影響遗锣,放射性物質(zhì)發(fā)生泄漏货裹。R本人自食惡果不足惜嗤形,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,343評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望弧圆。 院中可真熱鬧赋兵,春花似錦、人聲如沸搔预。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,919評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)拯田。三九已至历造,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間船庇,已是汗流浹背吭产。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,042評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留鸭轮,地道東北人臣淤。 一個(gè)月前我還...
    沈念sama閱讀 48,191評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像窃爷,于是被迫代替她去往敵國(guó)和親邑蒋。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,955評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • EventBus源碼分析 Android開(kāi)發(fā)中我們最常用到的可以說(shuō)就是EventBus了按厘,今天我們來(lái)深入研究一下E...
    BlackFlag閱讀 509評(píng)論 3 4
  • 簡(jiǎn)介 Android或者Java平臺(tái)下的一款高效的事件總線框架医吊。 版本 : org.greenrobot:even...
    雷小歪閱讀 311評(píng)論 0 1
  • 基于V3.1.1EventBus 官方地址EventBus GitHub地址 EventBus 是什么 概念:Ev...
    afree_閱讀 396評(píng)論 0 6
  • EventBus 是一個(gè)在 Android 開(kāi)發(fā)中使用的發(fā)布/訂閱事件總線框架 EventBus... 簡(jiǎn)化組件之...
    浪夠_閱讀 381評(píng)論 0 3
  • EventBus是在Android中使用到的發(fā)布-訂閱事件總線框架,基于觀察者模式逮京,將事件的發(fā)送者和接收者解耦卿堂,簡(jiǎn)...
    BrotherTree閱讀 407評(píng)論 0 1