I read some information about the class cluster template and understood the following:
the public cluster class provides an interface without a real implementation; other classes implement it for different cases;
has some similarities with the abstract Factory pattern: when we call the +classNameWith... method, depending on the arguments, it can select the most suitable subclass and return it.
For example, +[NSNumber numberWithDouble:1.0] will return an implementation for storing double values.
But what I did not understand: how -init... works -init... method of the open class of the cluster: [[NSNumber alloc] initWithDouble:1.0] , because after calling alloc it already allocates an instance of NSNumber , and not its subclass.
So, can anyone explain how the alloc-init method of a public cluster class actually works, and when does a particular subclass be created and returned?
design-patterns ios objective-c
Mikhail
source share