Đang chuẩn bị liên kết để tải về tài liệu:
Programming in Objective-C 2.0 edition phần 4
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Để hoàn thành việc chạy trường hợp thử nghiệm, bạn cũng nên cố gắng một năm đó là chia hết cho 4 và không theo 100.This là trái như một bài tập cho bạn . Chúng tôi đã đề cập rằng Mục tiêu-C cung cấp cho các lập trình viên một số tiền to lớn của sự linh hoạt trong biểu thức hình thành. | 168 Chapter 8 Inheritance Using the @class directive is more efficient because the compiler doesn t need to process the entire XYPoint.h file even though it is quite small it just needs to know that XYPoint is the name of a class. If you need to reference one of the XYPoint classes methods the @class directive does not suffice because the compiler would need more information it would need to know how many arguments the method takes what their types are and what the method s return type is. Let s fill in the blanks for your new XYPoint class and Rectangle methods so you can test everything in a program. First Program 8.4 shows the implementation file for your XYPoint class. First Program 8.4 shows the new methods for the Rectangle class. Program 8.4 Rectangle.m Added Methods import XYPoint.h - void setOrigin XYPoint pt origin pt - XYPoint origin return origin @end Following are the complete XYPoint and Rectangle class definitions followed by a test program to try them out. Program 8.4 XPoint.h Interface File import Foundation Foundation.h interface XYPoint NSObject int x int y @property int x y - void setX int xVal andY int yVal @end Extension Through Inheritance Adding New Methods 169 Program 8.4 XYPoint.m Implementation File import XYPoint.h implementation XYPoint synthesize x y - void setX int xVal andY int yVal x xVal y yVal @end Program 8.4 Rectangle.h Interface File import Foundation Foundation.h @class XYPoint interface Rectangle NSObject int width int height XYPoint origin property int width height - XYPoint origin - void setOrigin XYPoint pt - void setWidth int w andHeight int h - int area - int perimeter @end Program 8.4 Rectangle.m Implementation File import Rectangle.h implementation Rectangle synthesize width height - void setWidth int w andHeight int h 170 Chapter 8 Inheritance width w height h void setorigin Point pt origin pt int area return width height int perimeter return width height 2 Point origin return origin @end Program 8.4 Test Program .