TAILIEUCHUNG - Chapter 2: Structutal Patterns: Decorator, Proxy and Bridge

Sự kết hợp của ảnh gốc và một số nội dung mới hình thức một đối tượng mới. Trong bức ảnh thứ hai được hiển thị trong Hình 2-1, có bốn đối tượng: hình ảnh ban đầu cho thấy bên trái, đối tượng cung cấp một biên giới, và hai đối tượng thẻ với các dữ liệu khác nhau liên quan đến họ. Mỗi người trong số họ là một đối tượng trang trí. Cho rằng số cách khác nhau của hình ảnh trang trí là vô cùng tận, chúng ta có thể có nhiều đối tượng mới. Vẻ đẹp. | Figure 2-1. Decorator pattern illustration a plain photograph and b photograph with tags The combination of the original photo and some new content forms a new object. In the second image shown in Figure 2-1 there are four objects the original photo as shown to the left the object that provides a border and two tag objects with different data associated with them. Each of them is a Decorator object. Given that the number of ways of decorating photos is endless we can have many such new objects. The beauty of this pattern is that The original object is unaware of any decorations. There is no one big feature-laden class with all the options in it. The decorations are independent of each other. The decorations can be composed together in a mix-and-match fashion. Design Now we can specify the players in the Decorator pattern in a UML diagram shown in Figure 2-2. Because this is the first pattern we are describing in UML we ll take it slowly. The UML that we need for patterns in this book is covered in Chapter 1 and summarized in Table 1-1. The essential players in this UML diagram are Component An original class of objects that can have operations added or modified there may be more than one such class Operation An operation in IComponent objects that can be replaced there may be several operations 10 Chapter 2 Structural Patterns Decorator Proxy and Bridge IComponent The interface that identifies the classes of objects that can be decorated Component is one of these Decorator A class that conforms to the IComponent interface and adds state and or behavior there may be more than one such class Figure 2-2. Decorator pattern UML diagram The center of the UML diagram is the Decorator class. It includes two types of relationships with the IComponent interface Is-a The is-a relationshipis shown by a dotted arrow from the Decorator to IComponent indicating that Decorator realizes the IComponent interface. The fact that Decorator inherits from IComponent means that Decorator

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.