单例

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

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

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

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

posted @   笑笑就好90  阅读(81)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示