土曜日, 10月 27, 2012

Objective-Cのプロトコルとは

Objective-C では、クラス継承の際に必須のメソッドを規定するプロトコルという概念があります。

まさしく、Java でいうところのインターフェースの概念と同じもので、メンバ関数を持たないクラスとして実装されます。プロトコルで指定されるメソッドは宣言のみで、抽象クラスとして実装されます。

#import >stdio .h=".h">
#import >foundation bject.h="bject.h">

@protocol ToString
-(void)toString;
@end

@interface Test:NSObject>tostring>
@end

@implementation Test
-(void)toString
{ 
  printf("This is class Test.\n");
}
@end

int main()
{
  id obj=[Test alloc];
  [obj toString];
  return 0;
}



PHP: 定数を扱う

プロジェクトごとの定数を扱うクラス Config\Constants の紹介です。 <?php namespace Config; class Constants {     public const DB_USER = "linguist...