1,Factory methodIt is a classic design pattern in program design. It refers to defining only interfaces for creating objects in the base class and postponing the actual implementation to the subclass. Here, we will promote it a little. It refers to all static functions that generate and return an object. A classic factory method is like this:
Ccobject * factorymethod () {ccobject * ret = new ccobject (); // perform the necessary initialization operations on the RET object: ret-> autorelease (); return ;}
2. About object Value passing
When assigning an object to a pointer as a reference, in order to follow the memory management principle, we need to obtain the reference permission of the new object and release the reference of the old object.
Permission. In this case, the order of release () and retain () is particularly important.When other and object actually point to the same object, the first release () may trigger the collection of this object, which obviously does notWe want to see the situation, so we should first execute retain () to ensure that the other object is valid, and then release the old object:
Void someclass: setobject (ccobject * Other) {Other-> retain (); this-> Object-> release (); this-> Object = Other ;}
3,
Notes for Cocos2d-x