Tham khảo tài liệu ' a guide to matlab object oriented programming episode 2 part 2', 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ả | 194 A Guide to MATLAB Object-Oriented Programming 4 this 1 .mColorHsv 2 3 1 1 H S V of border default is blue 5 this 1 .mLineWidth 1 line weight normal 1 bold 3 6 this 1 .mLineHandle handle for shape s line plot 7 superior 8 inferior 9 parents 10 parent_list parents cLineStyle s fieldnames Whereas ctor_ini defines the collection of private variables fieldnames defines the collection of public variables. In this case there are only three Color Lineweight and LineHandle. The public variables and the values they hold come directly from the requirements. The code to implement fieldnames for these public variables is shown in Code Listing 86. Code Listing 86 Modular Code cLineStyle s 1 function names fieldnames this varargin 2 names 3 4 first fill up names with parent public names 5 parent_name parent_list get the parent name cellstr 6 for parent_name parent_list 7 names names fieldnames this. parent_name 1 varargin 8 end 9 10 returns the list of public member variable names 11 if nargin 1 12 names Color Linewidth LineHandle 13 else 14 switch varargin 1 15 case -full 16 names Color double array . 17 Linewidth positive integer . 18 LineHandle plot handle 19 case -possible 20 names Color double array 3x1 . 21 LineWidth positive integer . 22 LineHandle plot handle 23 Otherwise 24 error Unsupported call to fieldnames 25 end 26 end Constructing Simple Hierarchies with Composition 195 The parent-forwarding code in lines 4-8 is not necessary because parent_list returns an empty cellstr. It is included because it is part of the standard template. When fieldnames is called with one input argument line 12 returns a cellstr populated with the three public variable names. Lines 16-18 and 20-22 return additional information that depend respectively on -full and -possible flag values. In line 21 note the possible values for LineWeight are normal or bold . cLineStyle s get The public variable section for cLineStyle s get is shown in Code Listing 87. By .