[Biococoa-dev] the decorator pattern

Alexander Griekspoor mek at mekentosj.com
Sat Sep 11 03:14:46 EDT 2004


Hi Koen,

After you mentioned the "Design Patterns" book by Gamma et al. I 
decided to buy a second hand copy from Amazon ;-)
Unfortunately, I haven't had the time to read it, but one example I 
remembered from skimming through the book.
Guess which ;-)

Indeed the best example is NSScrollView in which you can place any 
other type of view. And in a way, I think BCDigest can be considered a 
decorator as well, the other name for this pattern is "wrapper". It's 
kind of a bag, holding other objects and has the ability to add 
functionality without the need to add to the class itself. BCDigest 
holds a number of BCSequences and adds the possibility to do a digest 
without putting the logic of doing digests into the BCSequence class.

I'm not sure if this helps us in here, but then again my experience is 
not much. If I go back to the question whether we need a BCFragment 
class (I think you were hinting to that), then perhaps a decorator 
could indeed help, although I would rather call it a wrapper in that 
case. The idea was to store not only the sequence, but also the enzymes 
that produced both ends and for example the original position in the 
uncut sequence. The solution we came up with was to have a BCFragment 
class that is a subclass of BCSequence which adds the needed variables 
to store the enzymes and position. And it would quickly mean three 
other classes, BCFragmentDNA/RNA/Protein. The 'decorator' pattern might 
indeed help, as we could make BCFragment normally descend of NSObject 
and act as a simple wrapper that stores a BCSequence (any type), the 
BCEnzymes which produce each end, and the position in the uncut 
sequence. The BCDigest class simply spits out BCFragments in this case.

  I think you're right Koen, this is indeed better than further 
subclassing BCSequence. Certainly because it would mean you can nicely 
keep things separated for all kinds of manipulations through the 
addition of single wrapper objects instead of getting tons of different 
BCSequence subclasses.

I'm not sure if the features/annotations would benefit from this 
approach, it somehow feels the wrong way around for those. There the 
BCSequence acts as a wrapper for a number of sequences, and these are 
also intrinsic parts of all BCSequence objects, guess therefore these 
belong just in the class itself. But if you can show otherwise, I'm 
looking forward to that....

Great suggestion!
Alex

Ps. perhaps I should really start reading the book to further mine new 
insights ;-)


Op 11-sep-04 om 3:19 heeft Koen van der Drift het volgende geschreven:

> Hi,
>
> One of the many software design patterns is the decorator pattern. 
> Basically the idea is to add additional functionality to an object 
> without subclassing. Usually the decoration takes place during 
> runtime, and therefore is dynamic, in contrast to subclassing which is 
> static. Real examples are adding a border to a shape in a drawing 
> program, or a style to a text (bold, italics).
>
> So maybe we should think about using the decorator pattern in BioCocoa 
> to add temporarily additional functionality to existing classes. For 
> instance a modification, annotation, or digest info.  After the 
> discussion with Alex about the subclasses after a digest, I still had 
> a feeling that all those subclasses aren't really necessary.
>
> Anyway, I will have to read more about this, to see how it exactly is 
> implemented (most sample code and tutorials I found is in Java and 
> very short), and if it is really useful for BioCocoa. I will post 
> later if I know more.
>
>
> Why do you guys think?
>
>
> cheers,
>
> - 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

*********************************************************


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

               4Peaks - For Peaks, Four Peaks.
        2004 Winner of the Apple Design Awards
                Best Mac OS X Student Product
              http://www.mekentosj.com/4peaks

*********************************************************




More information about the Biococoa-dev mailing list