类簇——Class Cluster

官方文档:
https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/ClassCluster.html

继承类簇会存在的问题:
http://www.cnblogs.com/pengyingh/articles/2359201.html

类簇如何实现的:
http://seanmurph.com/weblog/make-your-own-abstract-factory-class-cluster-in-objective-c/

简单归纳:
类簇使用抽象类工厂设计模式,重载alloc和init方法,使得返回的类实体并不是指定的类。因此继承类簇,并不能返回子类类型,自定义的方法也就不能实现了。
另外,返回的类实体,考虑到内存优化和管理等因素,还可能会被重复利用,好比NSString,和UIColor(实现主题功能,遇到的问题)。html

相关文章
相关标签/搜索