Applied Java Patterns Stephen phần 2

Chuyển tiếp để xử lý mặc định - phức tạp hơn so với mô hình cơ sở, phương pháp này sử dụng một xử lý sự kiện mặc định. Bất kỳ tin nhắn không được xử lý ở cấp thành phần, hoặc chuyển tiếp đến một số xử lý khác, sẽ được gửi đến xử lý mặc định. Bỏ qua bởi mặc định | Forward to default handler - More complex than the base pattern this approach uses a default event handler. Any message not explicitly handled at the component level or forwarded to some other handler will be sent to the default handler. Ignore by default - Any message that is not explicitly handled or forwarded is discarded. If the classes in the chain produce events that are not used in the application this can be an acceptable way to reduce chatter. However you must be careful in this approach to avoid inadvertently discarding messages that the system should handle. Related Patterns Related patterns include the Composite page 157 . Chain of Responsibility is often used with the Composite pattern. When both are used together the Composite pattern provides support for a tree-based structure and basic message propagation and the Chain of Responsibility provides rules for how some of the messages are propagated. In addition Composite tends to send messages down the tree from the root to the branches while Chain of Responsibility usually sends messages up the tree from branches to the root . Example Note For a full working example of this code example with additional supporting classes and or a RunPattern class see Chain of Responsibility on page 366 of the Full Code Examples appendix. The PIM can act as a project manager as well as a contact manager. This code example shows how to use the Chain of Responsibility pattern to retrieve information from within a project hierarchy. The Projectitem interface defines common methods for anything that can be part of a project. Example 1. import 2. import 3. public interface Projectitem extends Serializable 4. public static final String EOL STRING 5. public Projectitem getParent 6. public Contact getOwner 7. public String getDetails 8. public ArrayList getProjectItems 9. The interface defines the methods getParent getOwner .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.