I am raising objc and cocoa, which is usually my first serious action in programming.
I am disturbing the differences between the init with the method, which are called on the examples, and the methods of the factory, which are called in the classrooms.
First of all, why are they called "factory" methods, and have I dubbed "InitWith" methods to have a proper word?
Second, what is the functional difference? Is this just memory management implication (factory methods come back an autorespended object)?
For example, what is the actual difference between [NSString stringWithString: (NSString *) aString] and [[NSString alloc] initWithString: (NSString *) estring ] ?
The difference between the methods is described in coco: You are returned with the object-in with string: So it has to be released, but you do not have a return with string with string and so it is not necessary to release it (in addition, if you want to gain ownership of it, then you should keep it up).
The methods of the factory are called as they return the already created objects for you, usually the parameters you provide are used to configure the object, the programmer's For convenience.
Comments
Post a Comment