Use of factory pattern in Python?

Discussion in 'Python' started by Nathan Harmston, Dec 7, 2006.

  1. Hi,

    Im trying to find the best way to do a certain task and my so far I
    have found that using something similar to factory pattern might be
    the best bet.

    I m parsing a file to be stored as a graph (using NetworkX). Each row
    in the file corresponds to a node in the graph. However rows have
    different types and different numbers of attributes. ( and their
    corresponding nodes in the future will have methods )
    eg

    chr1 SGD gene 5 8 id=1 name=3 dbref=6
    chr1 SGD intron 5 6 id=5 notes="spam"
    chr1 SGD exon 7 8 id=5

    so I was thinking of having a factory class to return the individual
    objects for each row......ie

    class Factory():
    # if passed a gene return a gene object
    # if passed an intron return an intron object
    # if passed an exom return an exon object

    Is this a good way of doing this, or is there a better way to do this
    in Python, this is probably the way I d do it in Java.

    Many Thanks

    Nathan
     
    Nathan Harmston, Dec 7, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Medi Montaseri
    Replies:
    17
    Views:
    917
    Medi Montaseri
    Sep 3, 2003
  2. Gabriel Genellina

    Re: Use of factory pattern in Python?

    Gabriel Genellina, Dec 7, 2006, in forum: Python
    Replies:
    1
    Views:
    373
    Nick Craig-Wood
    Dec 7, 2006
  3. Jan Dries

    Re: Use of factory pattern in Python?

    Jan Dries, Dec 7, 2006, in forum: Python
    Replies:
    0
    Views:
    532
    Jan Dries
    Dec 7, 2006
  4. sunny
    Replies:
    1
    Views:
    479
    Salt_Peter
    Dec 7, 2006
  5. C#
    Replies:
    4
    Views:
    436
Loading...

Share This Page