CRC.Press A Guide to MATLAB Object Oriented Programming May.2007 Episode 2 Part 8

Tham khảo tài liệu ' a guide to matlab object oriented programming episode 2 part 8', kỹ thuật - công nghệ, cơ khí - chế tạo máy phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 314 A Guide to MATLAB Object-Oriented Programming environment pass-by-reference syntax can reduce code quality and interfere with debugging. If you press me I recommend that you use pass-by-reference very sparingly. Even so if you decide to include pass-by-reference syntax it s important to have a good strategy. In the examples that follow we will implement one possible strategy. Currently all functions in the shape hierarchy use standard pass-by-value syntax. Consequently all mutators must return a copy of the modified object and a user must assign the returned object to a variable. This works well whenever it is obvious that a function is a mutator. For some functions it is difficult to decide at a glance whether the function is a mutator. In the shape hierarchy draw is a mutator but this fact is easy to forget. Calling draw modifies mFigureHandle but mFig-ureHandle is an internal implementation detail. Clients should be shielded from internal details and pass-by-reference is another tool that can be used to help enforce the separation between public and private. The current implementation of draw includes the following test if nargout 1 warning draw must be called using obj draw obj else Since all side effects from draw are private a client might reasonably expect to call draw without assigning the return value. In the current implementation that would result in an error. The client doesn t get the desired result but at least the error message tells what to do. With pass-by-reference emulation draw might still perform a nargout test however the result of the test would no longer throw an error. Instead pass-by-reference emulation would be used to modify the input object in place. The change would be immediately reflected in the client s workspace. In the examples that follow we will modify draw by allowing it to be called as a mutator or with pass-by-reference syntax. Like member functions public member variables can include pass-by-reference capability. This .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
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.