mardi 19 mai 2015

Is it suggested not to import parent's or siblings' class header file in cocos2d?

For example, there're three classes, Aclass, Bclass, and Cclass. Aclass initializes some instances of Bclass and Cclass as different children. Normally I'll import Bclass.h and Cclass.h in Aclass.h or Alcass.m. So far Bclass and Cclass don't know each other yet. However there're cases for example Bclass needs to know Cclass's properties and methods. One way to do this is to import Cclass.h in Bclass.h or Bclass.m; later on Cclass needs to know about Bclass, then I'll import Bclass.h in Cclass.h or Cclass.m. Sometimes if there's "import cycle" that can't pass the compiling, then I may change one of the import from xx.h into @class Xclass.

Though this works, however I feel it's not the right or delegate way to do. So what's the best way to design if one class needs to know about it's siblings?

Aucun commentaire:

Enregistrer un commentaire