實現了責任鏈設計模式的 Java 類庫 - Commons Chain
Commons Chain 是一個實現了責任鏈設計模式的 Java 類庫。
示例代碼:
package org.apache.commons.chain.mailreader.commands; import org.apache.commons.chain.Command; import org.apache.commons.chain.Context; public class ProfileCheck implements Command { public Profile newProfile(Context context) { return new Profile(); } public boolean execute(Context context) throws Exception { Object profile = context.get(Profile.PROFILE_KEY); if (null == profile) { profile = newProfile(context); context.put(Profile.PROFILE_KEY, profile); } return false; } }
本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!