[Biococoa-dev] Factories
Alexander Griekspoor
mek at mekentosj.com
Sun Aug 29 17:17:38 EDT 2004
Koen,
John implemented 17 nucleotides in the BCSequenceDNA class, why doesn't
the same approach work for aminoacids? All the class methods like +
(BCAminoAcid *) alanine are in place isn't it? Why doesn't that work?
You just implement the equivalent of: aBase = [BCNucleotideDNA
baseForSymbol: [entry characterAtIndex: loopCounter]];
thus aminoAcidForSymbol:
which would be similar as well:
+ (id) aminoAcidForSymbol: (unichar)entry {
switch ( entry ) {
case 'A' :
case 'a' : {
return [BCAminoAcid alanine];
break;
}
case 'C' :
case 'c' : {
return [BCAminoAcid cysteine];
break;
}
etc...
The C switch statement is extremely lightweight in comparison to the
object messaging involved in the use of a dictionary.
For me it's fine if we even stick to John's way to instantiate all
aminoacids at once as well, pretty big chance you need more than one
aminoacid any way once one is called. But even if you want them
instantiated on a per symbol basis, you can easily do that in the class
method:
+ (BCAminoAcid *) alanine {
if ( adenosineRepresentation == nil )
INIT SHARED ALANINE HERE (initAminoAcidWithSymbol: 'A')
return adenosineRepresentation;
}
Again, given that the nucleotides come in 17 different forms and the
aminoacids in about 20, I don't see why diverge their implementations.
It will certainly help to setup the system if it already works for one
of the two types, we can focus on optimizing both systems at ones as
experience with one can be applied on the other as well, and we will be
able to create more shared methods in the superclasses.
Alex
Op 29-aug-04 om 1:31 heeft Koen van der Drift het volgende geschreven:
> Hi,
>
> Still thinking about the best way to implement a flyweight pattern to
> create symbols. I finally think I understand how this works and made a
> new class called BCAminoAcidFactory. Here's its implementation:
>
> #import "BCAminoAcidFactory.h"
>
> static NSMutableDictionary *aminoAcidDictionary;
>
> @implementation BCAminoAcidFactory
>
>
> - ( BCAminoAcid *)aminoAcidWithSymbol: (unichar) aSymbol
> {
> BCAminoAcid *aminoAcid = nil;
> NSString *symbolString = [NSString stringWithCharacters: &aSymbol
> length: 1];
>
> if ( aminoAcidDictionary == nil )
> {
> aminoAcidDictionary = [[NSMutableDictionary alloc] init];
> }
>
> aminoAcid = [aminoAcidDictionary objectForKey: symbolString];
>
> if ( aminoAcid == nil )
> {
> aminoAcid = [[BCAminoAcid alloc] initWithSymbol: aSymbol];
> [aminoAcidDictionary setObject: aminoAcid forKey: symbolString];
> }
>
> return aminoAcid;
> }
>
>
> This is in turn called by any object that needs an amino acid. So
> initWithSymbol is never called directly, alwayd through the factory
> object. If the aa already exists, it will return the one that's in the
> static dictionary, otherwise it'll create a new one.
>
> Let me know what you think, and if I overlooked something critical.
> I'll wait for comments before committing it to CVS.
>
>
> - Koen.
>
> _______________________________________________
> Biococoa-dev mailing list
> Biococoa-dev at bioinformatics.org
> https://bioinformatics.org/mailman/listinfo/biococoa-dev
>
>
*********************************************************
** Alexander Griekspoor **
*********************************************************
The Netherlands Cancer Institute
Department of Tumorbiology (H4)
Plesmanlaan 121, 1066 CX, Amsterdam
Tel: + 31 20 - 512 2023
Fax: + 31 20 - 512 2029
AIM: mekentosj at mac.com
E-mail: a.griekspoor at nki.nl
Web: http://www.mekentosj.com
iRNAi, do you?
http://www.mekentosj.com/irnai
*********************************************************
More information about the Biococoa-dev
mailing list