2011-04-24 programming►objectivec ObjectiveC中的单例设计模式 注意class method中什么时候用self,什么时候用super! 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556#import "PostOfficeProxy.h" #import "HTTPPostOffice.h" static PostOffice *_sharedPostOffice = nil; @implementation PostOfficeProxy @synthesize realPostOffice; + (PostOffice*)sharedPostOfficeProxy { NSLog(@"shared"); @synchronized([PostOffice class]) { if (nil == _sharedPostOffice) { [[self alloc] init]; } } return _sharedPostOffice; } + (id)allocWithZone:(NSZone *)zone { NSLog(@"alloc zone"); @synchronized([PostOffice class]) { if (nil == _sharedPostOffice) { _sharedPostOffice= [super allocWithZone:zone]; } } return _sharedPostOffice; } - (id)init { NSLog(@"init"); self = [super init]; if (nil != self) { self.realPostOffice = [[HTTPPostOffice alloc] init]; } return self; } - (id)copyWithZone:(NSZone *)zone { return self; } - (id)retain { return self; } - (unsigned)retainCount { return UINT_MAX; } - (void)release { //do nothing } - (id)autorelease { return self; } @end Neuer Java Socket编程中加入代理 Älter 编码导致序列化sql对象时出现StreamCurruptedException异常