Cocoa 接口的定义于检测
来源:互联网 发布:软件使用统计 编辑:程序博客网 时间:2024/04/28 18:40
//-------接口定义
@protocol Printing
-(void) print;
@end
---------
//----实现接口 Printing -------
//----接口中的print 方法不必写出来
@interface Fraction : NSObject <Printing,NSCopying> {
int numerator;
int denominator;
}
-(Fraction*) initWithNumerator:(int)n denominator:(int)d;
-(int) numerator;
-(int) denominator;
-(void) setNumerator:(int)n;
-(void) setDenominator:(int)n;
-(void) setNumeratorAndDenominator:(int) num
andDeno:(int) den;
@end
@interface Complex : NSObject<Printing>{
double real;
double image;
}
-(Complex*) initWithReal: (double) r andImage: (double) i;
-(void) setReal: (double) r;
-(void) setImage: (double) i;
-(void) setReal: (double) r andImage: (double) i;
-(double) real;
-(double) image;
@end
Fraction *frac = [[Fraction alloc] initWithNumerator: 3 denominator: 10];
Complex *comp = [[Complex alloc] initWithReal: 5 andImage: 15];
id <Printing> printable;
copyPrintable = frac;
// true
if ( [frac conformsToProtocol: @protocol( NSCopying )] == YES ) {
printf( "Fraction conforms to NSCopying/n" );
}
if ( [frac conformsToProtocol: @protocol( Printing )] == YES ) {
printf( "Fraction conforms to Printing/n" );
}
// false
if ( [comp conformsToProtocol: @protocol( NSCopying )] == YES ) {
printf( "Complex conforms to NSCopying/n" );
}
//true
if ( [comp conformsToProtocol: @protocol( Printing )] == YES ) {
printf( "Complex conforms to Printing/n" );
}
// free memory
[frac release];
[comp release];
============接口的定义于实现
- Cocoa 接口的定义于检测
- 接口只用于定义类型。
- 接口只用于定义类型。
- (19):接口只用于定义类型
- 网络接口的检测
- 第19条:接口只用于定义类型
- Effective java 第 19 条: 接口只用于定义类型
- 第19条:接口只用于定义类型
- 第19条:接口只用于定义类型
- Java学习笔记14:接口只用于定义类型
- effective java(19) 之接口只用于定义类型
- 接口定义的对象
- 接口的定义
- 图的接口定义
- List接口的定义
- Set接口的定义
- 接口模块的定义
- 接口定义的步骤
- 关于hypercall的实现
- “ JavaScript挑战赛--随机颜色”优胜代码
- PHP 与 ASP.NET 正面交锋
- 设计模式
- 从相册的列表中选择头象,并将其裁剪
- Cocoa 接口的定义于检测
- oracle update select
- cout格式输出的使用
- 通用传输平台开发实录【4】语言选择
- ubuntu中安装IBUS输入法
- pku 2413 How many Fibs? 【java高精度】
- VS2005中的代码格式化
- 怎样在JAVA文件中获取该项目的相对路径
- 无盘工作站