[Biococoa-dev] why placeholder classes was: BCSequence class cluster

Charles PARNOT charles.parnot at stanford.edu
Sun Jan 9 02:15:20 EST 2005


>>>I still don't understand the construction with these placeholder classes. Why do we need them, next to the subclasses we already have? (this is an educational question, not a critical one ;-)
>>>
>>>- Koen.
>>
>><snip>... I hope the shortness makes it clearer. I can make a longer version if you want ;-)
>
>Please do, because it is still very confusing to me.
>
>- Koen.

OK, I will try with questions and answers so I will force you to follow my twisted path of reasoning;-)

1. I have a class cluster BCSequence. BCSequence responds to all kind of methods, inlcuding -complement. I let the user know by having that method in the header.
But, pressured by John and Alex, I decide to make the subclass BCSequenceProtein public. How do I do it?

Well, I make the header file 'BCSequenceProtein.h' public, so the user can #import it and use BCSequenceProtein.


2. Oups, BCSequenceProtein.h does also import BCSequence.h, so the compiler thinks that BCSequenceProtein can respond to '-complement'. Well, and all the methods. So much for a strongly-typed sequence class!! What do I do??

OK, I remove -complement from the BCSequence.h header, and only put it in BCSequenceDNA.h, but not in BCSequenceProtein.h


3. Aïe, now BCSequence gets some compiler warnings when trying to use -complement. How do I prevent that??

Well, I go back to what I had before...


4. OK, but should I go back to step 1 and spend the rest of my life on it?

No.


5. Then what do I do?

You can't make BCSequenceProtein.h public, you have to create a fake placeholder class, say BCSeqProtein, that will be public, with the right set of methods in the header. The user only knows about this public header that does not inherit from BCSequence. So when using that header, you get a compiler warning if you call -complement.
However, under the hood, when you alloc such an object, you really get a BCSequenceProtein object, which hooks your object back into the class cluster at runtime.

I am kind of hoping that you were mostly missing points 1-4. So step 5 might still need some explanations... And step 5 might certainly have other answers.

should't you be sleeping??? (I hope this email helps;-)

Charles


-- 
Charles Parnot
charles.parnot at stanford.edu

Help science go fast forward:
http://cmgm.stanford.edu/~cparnot/xgrid-stanford/

Room  B157 in Beckman Center
279, Campus Drive
Stanford University
Stanford, CA 94305 (USA)

Tel +1 650 725 7754
Fax +1 650 725 8021



More information about the Biococoa-dev mailing list