Design pattern question

Karl Schmid schmid at
Wed Aug 21 03:20:20 EDT 2002


I would like to separate an abstraction from its implementation. I think 
this is called the Bridge pattern by Gamma et al. (or at least it is a part 
of a bridge pattern).

In particular, I would like to assemble a set of DNA sequences and have the 
option to chose among different assembly algorithms. I am not sure what the 
best way to do this would be:

class SequenceAssembler:
    def __init__(self,assembler_type):

        if assembler_type == 'cap3':
            # What should I do here?
        elif assembler_type == 'phrap':
            # What should I do here?

    def save_sequences():

class Cap3Assembler(SequenceAssembler):

    def run_assembler():
        # Cap3 specific instructions

class PhrapAssembler(SequenceAssembler):

    def run_assembler():
        # Phrap specific instructions

Now I would like to instantiate the abstract class, but to obtain an 
instance of either the Cap3Assembler or PhrapAssembler class depending on 
the assembler_type variable.

>>> assembler = SequenceAssembler(assembler_type)

Is this possible? 

Thank you in advance.

-- Karl Schmid

More information about the Python-list mailing list