[Biococoa-dev] Factories

Koen van der Drift kvddrift at earthlink.net
Sun Aug 29 19:01:38 EDT 2004


On Aug 29, 2004, at 5:17 PM, Alexander Griekspoor wrote:

> 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?

I'm sure it does work, actually it's already implemented in BCAminoAcid 
in CVS. I was just confused by all the different methods for each 
base/amino acid.  For instance this code:

+ (BCAminoAcid *) alanine {
     if ( alanineRepresentation == nil )
         [BCAminoAcid initAminoAcids];
     return alanineRepresentation;
}

Every time an amino acid representation is not present, initAminoAcids 
gets called and makes a representation for each amino acid. This just 
appeared redundant to me. So I started to read some more, and found 
that the combination of Singleton/Flyweight/Factory patterns is a 
widely used approach in OOP, especially when you deal with a large 
amount of similar objects.

So based on some sample code I read, I implemented smething similar in 
BCAminoAcid, and BCSequenceProtein. But I will also leave in the method 
that John uses for nucleotides.

- Koen.




More information about the Biococoa-dev mailing list