单例

单例模式:
是一种特殊的工厂方法,特殊在于只能生成唯一的对象,使用static来延长其作用域

命名格式: +(id)shared + 类名

+(id)shareStudent{
      static TRStudent *s = nil;
if( s == nil ){
      s = [[TRStudent alloc ] init ];
}
return s;
}

工厂方法也是需要声明的,不声明的方法是私有方法或者是重写的方法

posted @ 2017-08-22 20:26  笑笑就好90  阅读(87)  评论(0)    收藏  举报