What should be a sub-class of CCObject?

What should be a sub-class of CCObject?
0.0 0


Seems like a simple enough question — what should be a sub-class of CCObject?

Clearly, the CCSpites, CCTMXLayer and so on are CCObjects. Should other custom classes be as well?

* Should the game’s database connection be a CCObject?
* Should the game’s data models be CCObjects?

If you are making this decision, what criteria do you use to decide?

Are there pros and cons?

Thanks for reading …



Just in case you are not very experienced with C++, be careful about multiple inheritance (also called diamond of death) when inheriting several class.

I found no practical reason to not have a class inherit CCObject : with CCObject, you benefit automatically from the ref counting and your object can be used in CCArray and CCDictionary (which I love). It’s also much like what you would do on Objective-C (which cocos2d-x is heavily based on), where every object inherit from NSObject.

The only reason would be, perhaps, a slight gain in performances. But if you find yourself in that situation, chances are the problem won’t be coming from CCObject.