TAILIEUCHUNG - A Guide to MATLAB Object-Oriented Programming phần 3

Ví dụ, một giải pháp không hỗ trợ nhiều mức độ lập chỉ mục, và nó không hỗ trợ kiểm tra đối số. Thậm chí tồi tệ hơn, một trong những giải pháp bản đồ trực tuyến tất cả các biến thành viên tư nhân như công chúng. | Changing the Rules . in Appearance Only 51 varargout this. index 1 .subs Similarly the . case of subsasgn would include the following line this. index 1 .subs varargin 1 The one-line 1 1 mapping code works well as an introduction but is too simplistic for most classes. For example the one-line solution does not support multiple indexing levels and it doesn t support argument checking. Even worse the one-line solution maps every private member variable as public. It is easy to address each of these deficiencies by adding more code and checking more cases. By the end of this chapter we will have a good working knowledge of subsref and subsasgn but we will not yet arrive at their final implementation. The final implementation relies on first developing some of the other group-of-eight members. subsref Dot-Reference Attempt 1 One potential solution to the subsref challenge is shown in Code Listing 13. This solution is similar to the solution outlined in the MATLAB manuals and is more versatile than the previous one-liner. This approach might be okay for simple classes but for classes that are more complicated it needs improvement. The biggest downfall of the implementation in Code Listing 13 is the coupling between the dot-reference name and private variable names. It also doesn t take care of multiple index levels and is not as modular as we might like. Such complaints are easily remedied. It just takes a little more work to push it over the top. Code Listing 13 By-the-Book Approach to subref s Dot-Reference Case 1 switch index 1 .type 2 case . 3 switch index 1 .subs 4 case mSize 5 varargout 6 case mScale 7 varargout 8 case mColorRgb 9 varargout 10 otherwise 11 error Reference to non-existent field . 12 index 1 .subs . 13 end 14 case 15 code to deal with cell array of index values 16 case 17 code to deal with cell array of index values 18 otherwise 19 error Unexpected of index 1 .type 20 end Line 1 references .

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.