tailieunhanh - A Guide to MATLAB Object-Oriented Programming phần 9

Theo quy ước, khi nó tồn tại, điều này thường nên được đối số đầu tiên trong danh sách đối số. Với các biến số trong danh sách đối số đầu vào, đầu ra tên biến được thêm vào từ điển dữ liệu. Bình luận: giữ một văn bản mô tả chức năng. Mô tả văn bản sẽ được thêm vào các ý kiến tiêu đề khi chức năng được tạo ra. | 19 Composition and a Simple Container Class As a further demonstration of composition we make an initial foray into designing and implementing a general container class. A general container is different from an array because it can hold different types. A general container is different from a cell array because all objects must descend from the same parent. For example a general cShape container can hold both cStar and cDiamond objects because they both use cShape as a parent. A container is also different from a cell array because a container has a structure-like interface. The interface makes a container behave a lot like an object array. Rather than looping over each element in the container clients can use vector syntax. Often the loop still exists however it is now hidden behind the container s interface. Developing a set of standard containers compatible with the general computer-engineering literature or with National Institute of Standards NIST definitions would be an enormous undertaking. The goals for this chapter s container are much less ambitious. The primary goal is to demonstrate one potential use of composition. A secondary goal is to produce a container that might be useful as is or at least produce a container that can be easily improved. The container developed for this chapter isn t perfect but with what you already know you can fix all of its deficiencies. BUILDING CONTAINERS To implement a container several details are important. First we need to specify the object type held by the container. Any object that passes an isa test for the specified type will be allowed in. Thus objects of the specified type and objects using the specified type as a parent are okay to add to the container. For the example we will specify cShape as the object type. That will allow the container to hold cShape cStar and cDiamond objects. If we want to create new shape classes the container will hold them too. Of course these new classes must have cShape .

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
34    212    1    29-04-2024
2    110    0    29-04-2024
11    101    0    29-04-2024
165    86    0    29-04-2024
crossorigin="anonymous">
Đã 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.