Class Cluster

来源:互联网 发布:两个表格数据匹配重复 编辑:程序博客网 时间:2024/05/21 10:38

UIButton is not a class cluster at all. A class cluster is represented by a public abstract class, that means no instance variables, with a bunch of private concrete subclasses that provide the implementation of the abstract methods of the abstract class. UIButton on the other hand is a concrete class, none of its methods is abstract, and it has instance variables to store the value you pass through its arguments. The only problematic part is that +buttonWithType can instantiate subclasses instead of UIButton directly, thus it can be seen as a factory method, not a class-cluster

/**Subclassing UIButton is definitely dangerous, because UIButton not a single class but a class cluster. I highly recommend not doing this. According to Apple:

The class cluster architecture involves a trade-off between simplicity and extensibility: Having a few public classes stand in for a multitude of private ones makes it easier to learn and use the classes in a framework but somewhat harder to create subclasses within any of the clusters.

A new class that you create within a class cluster must:

-Be a subclass of the cluster’s abstract superclass

-Declare its own storage

-Override the superclass’s primitive methods

Instead of adding a property to the category, you can use associative references and add getter and setter methods to the category to simulate a property on the button.*/

Ref:
http://stackoverflow.com/questions/11475364/how-to-figure-out-how-many-times-a-uibutton-has-been-pressed
Class Cluster
http://stackoverflow.com/questions/5045672/create-uibutton-subclass

原创粉丝点击