Notes for Cocos2d-x

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.