Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

CRC.Press A Guide to MATLAB Object Oriented Programming May.2007 Episode 2 Part 6 docx
MIỄN PHÍ
Số trang
20
Kích thước
542.7 KB
Định dạng
PDF
Lượt xem
1666

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

Nội dung xem thử

Mô tả chi tiết

274 A Guide to MATLAB Object-Oriented Programming

18 >> star.Size = [2;3];

19 >> disp(star.Size')

20 2 3

21 >> star

22 star =

23 Size: [2x1 double]

24 ColorRgb: [3x1 double]

25 Points: [2x6 double]

26 LineWeight: 'normal'

27 Title: 'A Star is born'

28 >> fieldnames(star)

29 ans =

30 'Size'

31 'ColorRgb'

32 'Points'

33 'LineWeight'

34 'Title'

35 >> fieldnames(star, '-full')

36 ans =

37 ans =

38 'Size % double array (2x1)'

39 'ColorRgb % double array (3x1)'

40 'Points % double array (2xN)'

41 'LineWeight % normal, bold'

42 'Title % string'

43 >> fieldnames(star, '-possible')

44 ans =

45 'Size'

46 {1x1 cell}

47 'ColorRgb'

48 {1x1 cell}

49 'Points'

50 {1x1 cell}

51 'LineWeight'

52 {1x1 cell}

53 'Title'

54 {1x1 cell}

55 >> struct(star)

56 Size: [2x1 double]

57 ColorRgb: [3x1 double]

58 Points: [2x6 double]

59 LineWeight: 'normal'

60 Title: 'A Star is born'

61 >> star = [cStar cStar; cStar cStar];

62 >> size(star)

63 ans =

64 2 2

C911X_C018.fm Page 274 Friday, March 2, 2007 9:06 AM

Class Wizard Versions of the Shape Hierarchy 275

Attending to the myriad details is something that a CASE tool can do very well. Even this is

difficult unless there is a good organizational structure. The organizational structure advocated by

the preceding chapters results in good class implementation, and Class Wizard is very helpful in

maintaining that structure. This is particularly true when the class definition evolves. With Class

Wizard, evolution is a simple matter of adding elements to the definition and rebuilding the files.

Files managed by the tool are overwritten with the new definition, while handcrafted files are

untouched. The best balance is always maintained between standard idioms and a developer’s

creativity.

18.7 INDEPENDENT INVESTIGATIONS

1. Repeat the test-drive commands using cDiamond objects instead of cShape objects.

2. Modify the class interfaces to allow shapes to be rotated by an arbitrary angle. Use Class

Wizard to generate the initial versions of helper functions and public member functions.

3. Add other line-style features to cLineStyle, and expose these features so that clients

can use them with cStar and cDiamond objects (for example, dotted vs. solid lines).

4. Add a cCircle class to the hierarchy. Does cCircle inherit cShape or is there a

better relationship? Should /@cCircle/draw use polar instead of plot? How

would the use of polar change the organization?

65 >> [star.Size]

66 ans =

67 1 1 1 1

68 1 1 1 1

69 >> {star.Size}

70 ans =

71 [2x1 double] [2x1 double] [2x1 double] [2x1 double]

72 >>

73 >> disp(class(star))

74 cStar

75 >> disp(isa(star, 'cShape'))

76 1

77 >> disp(isa(star, 'cDiamond'))

78 0

C911X_C018.fm Page 275 Friday, March 2, 2007 9:06 AM

Tải ngay đi em, còn do dự, trời tối mất!