TAILIEUCHUNG - Applied Java Patterns Stephen phần 3

- Bất kỳ thông báo đó không phải là một cách rõ ràng xử lý hoặc chuyển tiếp là bỏ đi. Nếu các lớp trong chuỗi sản xuất các sự kiện không được sử dụng trong ứng dụng, điều này có thể là một cách chấp nhận được để giảm bớt nói nhảm. Tuy nhiên, bạn phải cẩn thận trong phương pháp này để tránh vô tình loại bỏ thông báo rằng hệ thống xử lý. | State Also known as Objects for States Pattern Properties Type Behavioral Level Object Purpose To easily change an object s behavior at runtime. Introduction An application often behaves differently depending on the values of its internal variables. For instance when you re working on a text file you need to periodically save your work. Most current text editors allow you to save a document only when something has changed in the text. As soon as you save the content the text is considered to be clean the file content is the same as the content currently on display. At this point the Save option is not available as it serves no purpose. Implementing this decision-making in the individual methods makes the code hard to maintain and read. The result is that these methods contain long if else statements. A common tactic is to store the state of an object in a single variable using constants for a value. With this approach the methods normally contain large switch case statements that are very similar in each method. Objects are state and behavior state is kept in its attributes and the behavior is defined in methods. The State pattern allows you to change the behavior of an object dynamically. This dynamic behavior is achieved by delegating all method calls that rely on certain values to a State object. Such a State object is state and behavior as well so that when you change State objects you also receive a different behavior. The methods in the specific State classes no longer have to use if else or switch statements the State object defines the behavior for one state. Applicability Use the State pattern when The object s behavior depends on its state and the state changes frequently. Methods have large conditional statements that depend on the state of the object. Description Objects that have different behavior based on their current state might be difficult to implement without the State pattern. As mentioned before implementation without using the State pattern .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.