singletons专题

Singletons in Cocoa, are they evil?

故事 这事是这样的,去年我在上课的时候,和老师讨论了一下关于架构的问题,我是开发Cocoa/iOS的,老师是开发Web的,而老师是一个坚定的singletons are evil的拥护者,我和他说了我的App的架构,直接被他一顿猛劈,强烈的谴责了我使用Singletons,我回应说,这个pattern在Cocoa里是大量使用的,结果被搞了一句“用的多的就是对的么?你回去多学习一下再来讨论吧”

Objective C iOS Weak Singletons

Temporary shared memory management is always a bit of a difficult problem to solve. There are various well known ways of dealing with this problem but recently i’ve come across a novel solution to thi

实现“带寿命的Singletons”

鸡生蛋、蛋生鸡问题不必纠结,只需要仔细操控PTrackerArray,看代码 namespace  Private{ class LifetimeTracker{ public: LifetimeTracker(unsigned int x):longervity__(x){} vitual ~LifetimeTracker()=0; friend inline  bool Compa

Singletons

构造函数是private,客户端无法产生Singletons,但Instance()使得其编译期就得以实施 class Singleton{ public : static Singleton * Instance(){ if(!pInstance_) pInstance_=new Singleton; return pInstance_; } }