責(zé)任鏈模式(Chain of Responsibility?Pattern)
1. 概念
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.Chain the receiving objects and pass the request along the chain until an object handles it.
使多個(gè)對象有機(jī)會處理請求,從而避免了請求的發(fā)送者和接收者之間的耦合關(guān)系 。將這些對象連成一個(gè)鏈,并沿著這條鏈傳遞請求简僧,知道有對象處理它為止。
2. 應(yīng)用場景--比如:AI語義識別(采用多個(gè)場景parse過濾鏈機(jī)制)
3. 優(yōu)點(diǎn)
最顯著的優(yōu)點(diǎn)就是將請求和處理分開,請求者可以不用知道是誰處理的牺弄,處理者可以不用知道請求的全貌,兩者解耦宜狐。
4. 缺點(diǎn)
避免超長鏈的出現(xiàn)
5. 代碼實(shí)踐:
JDK:?
?java.util.logging.Logger#log()
?javax.servlet.Filter#doFilter()
Android:?TBD